[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
gcc-bugzilla@gcc.gnu.org
Tue Jan 25 11:15:41 GMT 2022
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.
More information about the Gcc-bugs
mailing list