https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123957
Bug ID: 123957
Summary: Using `extern "C"` directive inside anonymous
namespace results in mangled name
Product: gcc
Version: 15.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mike at sillyhouse dot net
Target Milestone: ---
The following minimal example fails to compile with GCC 15.2.1.
Using Fedora 43 but verified behaviour at at https://gcc.godbolt.org/.
Bug present in GCC 15.1 and 15.2.
Error given is: undefined reference to `(anonymous namespace)::testval'.
Expect `testval` symbol to be generated, but instead we get
`_ZN12_GLOBAL__N_17testvalE`.
#include <stdio.h>
namespace
{
__asm__(".type testval, @object\n"
"testval:\n"
".long 0x2badf00d\n");
extern "C" const unsigned testval; ///<< Problem line
} // namespace
int main()
{
printf("testval = 0x%08x\n", testval);
return 0;
}