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

            Bug ID: 127321
           Summary: -Wsfinae-incomplete not reverted by `#pragma GCC
                    diagnostic pop`
           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: ---

```cpp
template<int n>
struct registry {
    friend consteval auto injected(registry);
};

template<int n, typename T>
struct inject {
    friend consteval auto injected(registry<n>) { return T{}; }
};

template<int n, typename = decltype([]{})>
consteval int query1() {
    if constexpr (requires (registry<n> r) { injected(r); }) {
        return sizeof(injected(registry<n>{}));
    } else {
        return 0;
    }
}

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wsfinae-incomplete=0"
template<int n, typename = decltype([]{})>
consteval int query2() {
    if constexpr (requires (registry<n> r) { injected(r); }) {
        return sizeof(injected(registry<n>{}));
    } else {
        return 0;
    }
}
#pragma GCC diagnostic pop

template<int n, typename = decltype([]{})>
consteval int query3() {
    if constexpr (requires (registry<n> r) { injected(r); }) {
        return sizeof(injected(registry<n>{}));
    } else {
        return 0;
    }
}

static_assert(query1<0>() == 0);
static_assert(query2<0>() == 0);
static_assert(query3<0>() == 0);

inject<0, int> i;

static_assert(query1<0>() == 4);
static_assert(query2<0>() == 4);
static_assert(query3<0>() == 4);
```

Flags: "-std=c++26 -Wno-non-template-friend"
Compiling this produces no warnings
Godbolt: https://godbolt.org/z/v3WGqhP7e

If we comment out the `pragma diagnostic warning` line,
we get a warning related to `query1`.
Godbolt: https://godbolt.org/z/nzMqc3oaY

Reply via email to