public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: Disable -Wignored-qualifiers for template args [PR107492]
Date: Thu, 3 Nov 2022 15:22:12 -0400	[thread overview]
Message-ID: <8278b3b0-6af7-8c1a-0aad-a093419d7672@redhat.com> (raw)
In-Reply-To: <20221101170156.52672-1-polacek@redhat.com>

On 11/1/22 13:01, Marek Polacek wrote:
> 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
> 
> I'm of the mind that we should disable the warning for template
> arguments, as in the patch below.

Hmm, I'm not sure why we would want to treat template arguments 
differently from other type-ids.  Maybe only warn if funcdecl_p?

> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> 	PR c++/107492
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_template_type_arg): Suppress -Wignored-qualifiers
> 	warning.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/warn/Wignored-qualifiers3.C: New test.
> ---
>   gcc/cp/parser.cc                                 |  4 ++++
>   gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C | 12 ++++++++++++
>   2 files changed, 16 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e0e3cf3eaf6..54ad4b98ed3 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -24334,6 +24334,10 @@ cp_parser_template_type_arg (cp_parser *parser)
>     const char *saved_message = parser->type_definition_forbidden_message;
>     parser->type_definition_forbidden_message
>       = G_("types may not be defined in template arguments");
> +  /* It's wrong to issue a -Wignored-qualifiers warning for
> +      static_assert(!is_same_v<void(*)(), const void(*)()>);
> +     because there the qualifier matters.  */
> +  warning_sentinel w (warn_ignored_qualifiers);
>     r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL);
>     parser->type_definition_forbidden_message = saved_message;
>     if (cxx_dialect >= cxx14 && !flag_concepts && type_uses_auto (r))
> diff --git a/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
> new file mode 100644
> index 00000000000..5696feaaefe
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
> @@ -0,0 +1,12 @@
> +// PR c++/107492
> +// { dg-do compile { target c++14 } }
> +// { dg-additional-options "-Wignored-qualifiers" }
> +
> +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" }
> 
> base-commit: e7310e24b1c0ca67b1bb507c1330b2bf39e59e32


  reply	other threads:[~2022-11-03 19:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 17:01 Marek Polacek
2022-11-03 19:22 ` Jason Merrill [this message]
2022-11-15  0:33   ` [PATCH v2] " Marek Polacek
2022-11-15 22:10     ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8278b3b0-6af7-8c1a-0aad-a093419d7672@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).