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

            Bug ID: 127493
           Summary: reflection: source_location_of does not like class
                    members
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.lazaric.gcc at gmail dot com
  Target Milestone: ---

Flags: "-std=c++26 -O3 -freflection"

```cpp
#include <meta>

struct S {
    void fn(int) {}
};

consteval {
    auto refl = ^^S::fn;
    auto loc = source_location_of(refl);
    __builtin_constexpr_diag(0, "", loc.file_name());
    __builtin_constexpr_diag(0, "", std::to_string(loc.line()));
}
```

Prints:
```
<source>:10:29: note: constexpr message: 
<source>:11:29: note: constexpr message: 0
```

https://godbolt.org/z/j1h6EsceW

```cpp
#include <meta>

struct S {
    using X = int;
};

consteval {
    auto refl = ^^S::X;
    auto loc = source_location_of(refl);
    __builtin_constexpr_diag(0, "", loc.file_name());
    __builtin_constexpr_diag(0, "", std::to_string(loc.line()));
}
```

This errors:
```
<source>:12:1:   in 'constexpr' expansion of '<lambda()> static()'
   12 | }
      | ^
<source>:10:29: error: request for member 'size' in '&"<source>"[0]', which is
of non-class type 'const char*'
   10 |     __builtin_constexpr_diag(0, "", loc.file_name());
      |     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
<source>:10:29: error: constexpr string must be a string literal or object with
'size' and 'data' members
```

https://godbolt.org/z/63o6GY4e7

Reply via email to