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++: delayed noexcept in member function template [PR99980]
Date: Thu, 16 Dec 2021 16:15:16 -0500	[thread overview]
Message-ID: <0d9c7a6a-b391-a372-01cc-555bcf737433@redhat.com> (raw)
In-Reply-To: <20211216160014.24338-1-polacek@redhat.com>

On 12/16/21 11:00, Marek Polacek wrote:
> Some time ago I noticed that we don't properly delay parsing of
> noexcept for member function templates.  This patch fixes that.
> 
> It didn't work because even though we set CP_PARSER_FLAGS_DELAY_NOEXCEPT
> in cp_parser_member_declaration, member template declarations take
> a different path: we call cp_parser_template_declaration and return
> prior to setting the flag.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> 	PR c++/99980
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.c (cp_parser_single_declaration): Maybe pass
> 	CP_PARSER_FLAGS_DELAY_NOEXCEPT down to cp_parser_init_declarator.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp0x/noexcept71.C: New test.
> ---
>   gcc/cp/parser.c                         |  7 +++++-
>   gcc/testsuite/g++.dg/cpp0x/noexcept71.C | 31 +++++++++++++++++++++++++
>   2 files changed, 37 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept71.C
> 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index c2564e51e41..c19e5f1359d 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -31673,8 +31673,13 @@ cp_parser_single_declaration (cp_parser* parser,
>         && (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)
>   	  || decl_specifiers.type != error_mark_node))
>       {
> +      int flags = CP_PARSER_FLAGS_TYPENAME_OPTIONAL;
> +      /* We don't delay parsing for friends, though CWG 2510 may change
> +	 that.  */
> +      if (member_p && !(friend_p && *friend_p))
> +	flags |= CP_PARSER_FLAGS_DELAY_NOEXCEPT;
>         decl = cp_parser_init_declarator (parser,
> -					CP_PARSER_FLAGS_TYPENAME_OPTIONAL,
> +					flags,
>   				        &decl_specifiers,
>   				        checks,
>   				        /*function_definition_allowed_p=*/true,
> diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept71.C b/gcc/testsuite/g++.dg/cpp0x/noexcept71.C
> new file mode 100644
> index 00000000000..361d6ad7b60
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept71.C
> @@ -0,0 +1,31 @@
> +// PR c++/99980
> +// { dg-do compile { target c++11 } }
> +
> +#define SA(X) static_assert(X, #X)
> +
> +struct S {
> +  template<typename T>
> +  void f(T) noexcept(B);
> +
> +  struct N {
> +    template<typename T>
> +    void f2(T) noexcept(B);
> +  };
> +
> +  static constexpr bool B = true;
> +};
> +
> +S s;
> +SA(noexcept(s.f(10)));
> +S::N n;
> +SA(noexcept(n.f2(10)));
> +
> +struct Bad {
> +  template<typename T>
> +  using U = void() noexcept(B); // { dg-error "not declared" }
> +
> +  template<typename T>
> +  friend void friendo() noexcept(B); // { dg-error "not declared" }
> +
> +  static constexpr bool B = true;
> +};
> 
> base-commit: 41cc28405c74a5ec59c6725274aaedefa9ca5887


      reply	other threads:[~2021-12-16 21:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 16:00 Marek Polacek
2021-12-16 21:15 ` Jason Merrill [this message]

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=0d9c7a6a-b391-a372-01cc-555bcf737433@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).