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

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).