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

            Bug ID: 109494
           Summary: inline const variables interfere with source_location
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oliver.rosten at googlemail dot com
  Target Milestone: ---

The bug, (for which I'm not sure if it is a front end problem or a library
problem), is reproduced here: https://github.com/ojrosten/SourceLoc

The project comprises three files in the Test directory:

Main.cpp
Test.cpp
Test.hpp

Both the cpps depend on the hpp. The latter contains an unused variable

inline const std::string foo{};

The presence of this seems to cause:

1. The appearance of a warning: "ld: warning: direct access in function ...
from file ... to global weak symbol ... from file ... means the weak symbol
cannot be overridden at runtime..."

2. std::source_location::current() to misbehave: building and running causes
the path to Main.cpp to be output twice, whereas it should just be printed
once, with the path to Test.cpp appearing second.

Any of the following cures both of the problems:

1. Removing foo;

2. Removing inline;

3. Replacing const with constexpr

In the much more complex project where I first encountered this, I reliably got
a segmentation fault. I was able to cure this by removing inline in a handful
of places.

Reply via email to