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

            Bug ID: 107492
           Summary: Unhelpful -Wignored-qualifiers warning in template
                    specialization
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

GCC warns about this with -Wextra:

template<typename T> struct S { };
template<> struct S<void(*)()> { };
template<> struct S<const void(*)()> { };

template<typename T, typename U> constexpr bool is_same_v = false;
template<typename T> constexpr bool is_same_v<T, T> = true;

static_assert( ! is_same_v< void(*)(), const void(*)() > );


spec.cc:3:21: warning: type qualifiers ignored on function return type
[-Wignored-qualifiers]
    3 | template<> struct S<const void(*)()> { };
      |                     ^~~~~
spec.cc:8:40: warning: type qualifiers ignored on function return type
[-Wignored-qualifiers]
    8 | static_assert( ! is_same_v< void(*)(), const void(*)() > );
      |                                        ^~~~~


The warning is wrong, the qualifiers are not ignored here. The two types are
distinct, as shown by the fact that the explicit specializations are not
redefinitions of each other, and the static assert passes.

Reply via email to