https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101775
Bug ID: 101775 Summary: G++ drops namespace prefix of argument in the referenced function symbol Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- When g++ builds following code, the function foo() referenced by this program is compiled to symbol ``foo(VecReg&)``, which should be ``foo(MyISA::VecReg&)`` with the namespace prefix. This results in a linking error. ``` // test.cc #include <cstdint> #include <cstdlib> namespace MyISA { typedef struct { uint8_t data[64]; } VecReg; } void foo(MyISA::VecReg &v); using MyISA::VecReg; class A { VecReg v; public: void test(); }; typedef MyISA::VecReg VecReg; void A::test() { foo(v); } int main() { A a; a.test(); } ``` ``` // foo.cc #include <cstdint> namespace MyISA { typedef struct { uint8_t data[64]; } VecReg; } void foo(MyISA::VecReg &v) { v.data[0] = 42; } ``` $ g++ -c test.cc ; g++ -c foo.cc ; g++ -o main test.o foo.o /usr/bin/ld: test.o: in function `A::test()': test.cc:(.text+0x14): undefined reference to `foo(VecReg&)' $ nm -C test.o foo.o test.o: U _GLOBAL_OFFSET_TABLE_ 000000000000001b T main U __stack_chk_fail U foo(VecReg&) 0000000000000000 T A::test() foo.o: 0000000000000000 T foo(MyISA::VecReg&)