https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129234

            Bug ID: 129234
           Summary: [16 Regression] [modules] conflicting declaration
                    'struct A' when a class forward-declared and
                    befriended in an imported module is defined in the
                    importing TU
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bas.van.dijk at cern dot ch
  Target Milestone: ---

// a.h
class A;
class C { friend A; };

// m.cppm
module;
#include "a.h"
export module m;
export using ::C;

// t.cpp
import m;
C* p;          // the lookup of C triggers the error
class A {};

$ g++ -std=c++20 -fmodules-ts -x c++ -c m.cppm
$ g++ -std=c++20 -fmodules-ts -c t.cpp

GCC 16.1.0:

t.cpp:3:7: error: conflicting declaration 'struct A'
a.h:2:7: note: previous declaration as 'class A'

GCC 15.2.0 compiles both files (the only error is the missing main when linking
a program).

Both declarations of A are in the global module, so I expect the definition in
the importer to be valid. The message says 'struct A' although A is declared as
a class, which looks as if a second type was created for A.

This is not bisected. It may be related to PR 99000 and PR 122053 / PR 124485.
PR 127346 also reports "conflicting declaration", but for an extern "C++" class
whose definition is reachable but not visible, which is a different trigger.

This breaks the Gaudi framework (CERN, LHCb software), which imports its kernel
headers through a wrapper module: IService.h contains "class ServiceManager;
friend class ServiceManager;" and GaudiCoreSvc defines ServiceManager, which
gives "conflicting declaration 'struct ServiceManager'" with GCC 16 and
compiled with GCC 15.

Reply via email to