Skip to content
Snippets Groups Projects
Commit ed1797dd authored by Marek Polacek's avatar Marek Polacek
Browse files

c++: Disable -Wignored-qualifiers for template args [PR107492]

It seems wrong to issue a -Wignored-qualifiers warning for code like:

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

because there the qualifier matters.  Likewise in template
specialization:

  template<typename T> struct S { };
  template<> struct S<void(*)()> { };
  template<> struct S<const void(*)()> { }; // OK, not a redefinition

And likewise in other type-id contexts such as trailing-return-type:

  auto g() -> const void (*)();

This patch limits the warning to the function declaration context only.

	PR c++/107492

gcc/cp/ChangeLog:

	* decl.cc (grokdeclarator): Only emit a -Wignored-qualifiers warning
	when funcdecl_p.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wignored-qualifiers3.C: New test.
parent c717a92d
No related branches found
No related tags found
No related merge requests found
......@@ -13038,7 +13038,11 @@ grokdeclarator (const cp_declarator *declarator,
 
if (type_quals != TYPE_UNQUALIFIED)
{
if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))
/* It's wrong, for instance, to issue a -Wignored-qualifiers
warning for
static_assert(!is_same_v<void(*)(), const void(*)()>);
because there the qualifier matters. */
if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
"qualifiers ignored on function return type");
/* [dcl.fct] "A volatile-qualified return type is
......
// PR c++/107492
// { dg-do compile { target c++14 } }
// { dg-additional-options "-Wignored-qualifiers" }
// Here the 'const' matters, so don't warn.
template<typename T> struct S { };
template<> struct S<void(*)()> { };
template<> struct S<const void(*)()> { }; // { dg-bogus "ignored" }
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(*)() >, ""); // { dg-bogus "ignored" }
// Here the 'const' matters as well -> don't warn.
auto g() -> const void (*)(); // { dg-bogus "ignored" }
auto g() -> const void (*)() { return nullptr; } // { dg-bogus "ignored" }
// Here as well.
const void (*h)() = static_cast<const void (*)()>(h); // { dg-bogus "ignored" }
// But let's keep the warning here.
const void f(); // { dg-warning "ignored" }
const void f() { } // { dg-warning "ignored" }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment