public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104221] New: member functions defined in separate files of classes declared in module partitions won't compile
@ 2022-01-25 11:15 f.b.brokken at rug dot nl
2024-01-04 5:03 ` [Bug c++/104221] " nathanieloshead at gmail dot com
0 siblings, 1 reply; 2+ messages in thread
From: f.b.brokken at rug dot nl @ 2022-01-25 11:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104221
Bug ID: 104221
Summary: member functions defined in separate files of classes
declared in module partitions won't compile
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: f.b.brokken at rug dot nl
Target Milestone: ---
The following source file (full.cc) compiles OK:
-----------------------------
export module mod:partition;
export class Data
{
int d_value = 10;
public:
int value() const;
};
int Data::value() const
{
return d_value;
}
void fun();
-----------------------------
The function fun() can be implemented in a separate file, and also compiles OK
(fun.cc):
-------------------------
module;
#include <iostream>
module mod:partition;
using namespace std;
void fun()
{
cout << "hi\n";
}
-------------------------
When implementing int Data::value() const in a separate file a compilation
error results.
Here's the modified module interface file (partition.cc):
-----------------------------
export module mod:partition;
export class Data
{
int d_value = 10;
public:
int value() const;
};
void fun();
-----------------------------
and the source defining int Data::value() (value.cc):
------------------------
module mod:partition;
int Data::value() const
{
return d_value;
}
------------------------
The function void fun() compiles OK.
When compiling
g++ --std=c++20 -Wall -Wextra -fno-strict-aliasing -fwrapv -c -fmodules-ts \
partition.cc fun.cc value.cc
using g++-12 on an updated Debian linux system
(g++ (Debian 12-20211217-1) 12.0.0 20211217 (experimental) [master
r12-6027-g774269aa4b9] the compiler reports:
--------------------------------------------------------------------------
value.cc:3:5: error: ‘Data’ has not been declared
3 | int Data::value() const
| ^~~~
value.cc:3:19: error: non-member function ‘int value()’ cannot have
cv-qualifier
3 | int Data::value() const
| ^~~~~
value.cc: In function ‘int value()’:
value.cc:5:12: error: ‘d_value’ was not declared in this scope; did you mean
‘value’?
5 | return d_value;
| ^~~~~~~
| value
value.cc: At global scope:
value.cc:1:1: warning: not writing module ‘mod:partition’ due to errors
1 | module mod:partition;
| ^~~~~~
--------------------------------------------------------------------------
If any additional information is required, please let me know.
Kind regards,
Frank.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/104221] member functions defined in separate files of classes declared in module partitions won't compile
2022-01-25 11:15 [Bug c++/104221] New: member functions defined in separate files of classes declared in module partitions won't compile f.b.brokken at rug dot nl
@ 2024-01-04 5:03 ` nathanieloshead at gmail dot com
0 siblings, 0 replies; 2+ messages in thread
From: nathanieloshead at gmail dot com @ 2024-01-04 5:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104221
Nathaniel Shead <nathanieloshead at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nathanieloshead at gmail dot com
--- Comment #1 from Nathaniel Shead <nathanieloshead at gmail dot com> ---
I think this is IFNDR; you cannot have more than one partition with the same
name. See https://eel.is/c++draft/module.unit#3:
> A module partition is a module unit whose module-declaration contains
> a module-partition. A named module shall not contain multiple module
> partitions with the same module-partition. All module partitions of a
> module that are module interface units shall be directly or indirectly
> exported by the primary module interface unit ([module.import]).
> No diagnostic is required for a violation of these rules.
And in particular, unlike a module implementation unit, a module partition does
not implicitly import anything; see https://eel.is/c++draft/module.unit#8 which
says:
> A module-declaration that contains neither an export-keyword nor a
> module-partition implicitly imports the primary module interface unit
> of the module as if by a module-import-declaration.
So this is working as specified. I don't think there'd be any good way of
improving the diagnostics for this either.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-04 5:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 11:15 [Bug c++/104221] New: member functions defined in separate files of classes declared in module partitions won't compile f.b.brokken at rug dot nl
2024-01-04 5:03 ` [Bug c++/104221] " nathanieloshead at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).