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

            Bug ID: 124382
           Summary: [reflection] Erroneous result of
                    std::meta::has_identifier with parameter of a
                    specialized function template following friend
                    injection
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: friedkeenan at protonmail dot com
  Target Milestone: ---

The following code should compile, but does not:
```
#include <meta>

template<typename>
void function(int original_name);

template<typename>
struct friendly {
    friend void function<int>(int friendly_name);
};

/* In order to instantiate the template. */
constexpr inline auto size = sizeof(friendly<int>);

static_assert(not has_identifier(
    parameters_of(^^function<int>)[0]
));
```
Godbolt link: https://godbolt.org/z/as8o1rThn

Because the friend declares a specialization of the function using a different
parameter name than was originally declared, then std::meta::has_identifier
should return false.

If one removes the templating of the `friendly` struct, then it successfully
compiles:
```
#include <meta>

template<typename>
void function(int original_name);

struct friendly {
    friend void function<int>(int friendly_name);
};

static_assert(not has_identifier(
    parameters_of(^^function<int>)[0]
));
```
Godbolt link: https://godbolt.org/z/qcx4zGjWs

Both of these examples compile successfully when using the experimental Clang
reflection branch.
  • [Bug c++/124382] New: [refl... friedkeenan at protonmail dot com via Gcc-bugs

Reply via email to