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

            Bug ID: 93093
           Summary: __builtin_source_location reports values for default
                    arguments not aligned with the Standard
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: phdofthehouse at gmail dot com
  Target Milestone: ---

Consider the following example from the C++ Standard N4842 (nice website
version: eel.is/c++draft/support.srcloc#cons-4):

===========

struct s {
  source_location member = source_location::current();
  int other_member;
  s(source_location loc = source_location::current())
    : member(loc)         // values of member refer to the location of the
calling function ([dcl.fct.default])
  {}
  s(int blather) :        // values of member refer to this location
    other_member(blather)
  {}
  s(double)              // values of member refer to this location
  {}
};
void f(source_location a = source_location::current()) {
  source_location b = source_location::current();       // values in b refer to
this line
}

void g() {
  f();                   // f's first argument corresponds to this line of code

  source_location c = source_location::current();
  f(c);                  // f's first argument gets the same values as c, above
}

===========

When source_location is implemented with __builtin_source_location, code like
the above does not report those locations. s{}.member does not refer to the
calling location, s(2.0).member does not refer to the constructor declaration
s, and s(1).member does not refer to that location, and so forth.

Some talking on IRC revealed that this might be because of constant evaluation
/ constant folding, changing how the source location attribute behaves in
instances like these. This also affects the patch at
https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01579.html whose tests fail in
both static_assert and regular runtime VERIFYs.

Reply via email to