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

            Bug ID: 115194
           Summary: [modules] "reference to <symbol> is ambiguous" when
                    multiple paths to same symbol exist through module
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickbegg at gmail dot com
  Target Milestone: ---

This code example was reduced from Boost's multi_index_container.

When referencing symbols via modules and using statements, gcc gets tripped up
with different routes to the same symbol. 

When #including clean.hpp directly into main.cpp, this compiles ok.:

/// clean.hpp :

namespace NS1 { namespace NS2 {
class Thing {};
} // NS2
using NS2::Thing;
} // NS1

/// modA.mpp:
module;

#include "clean.hpp"

export module modA;

export namespace NS1 {
using ::NS1::Thing;
namespace NS2 {
} }

/// main.cpp:

#if 0
#include "clean.hpp"
#else
import modA;
#endif

using NS1::Thing;
using namespace NS1::NS2;
Thing thing;

///

Tested with gcc trunk / 15.0.0 20240522 (revid
1a5e4dd83788ea4c049d354d83ad58a6a3d747e6)

/home/nick/inst/gcc-trunk-debug/bin/g++   -fdiagnostics-color=always -g
-std=gnu++23 -MD -MT CMakeFiles/moduleMin.dir/main.cpp.o -MF
CMakeFiles/moduleMin.dir/main.cpp.o.d -fmodules-ts
-fmodule-mapper=CMakeFiles/moduleMin.dir/main.cpp.o.modmap -MD
-fdeps-format=p1689r5 -x c++ -o CMakeFiles/moduleMin.dir/main.cpp.o -c
/home/nick/src/moduleMin/main.cpp
/home/nick/src/moduleMin/main.cpp:9:1: error: reference to ‘Thing’ is ambiguous
    9 | Thing thing;
      | ^~~~~
In file included from /home/nick/src/moduleMin/modA.mpp:3,
of module modA, imported at /home/nick/src/moduleMin/main.cpp:4:
/home/nick/src/moduleMin/clean.hpp:5:7: note: candidates are: ‘class
NS1::NS2::Thing@modA’
    5 | class Thing {};
      |       ^~~~~
/home/nick/src/moduleMin/clean.hpp:5:7: note:                 ‘class
NS1::NS2::Thing@modA’

Reply via email to