c++: Failure to delay noexcept parsing with ptr-operator [PR100752]

Message ID 20210609002523.1256033-1-polacek@redhat.com
State New
Headers show
Series
  • c++: Failure to delay noexcept parsing with ptr-operator [PR100752]
Related show

Commit Message

Jason Merrill via Gcc-patches June 9, 2021, 12:25 a.m.
We weren't passing 'flags' to the recursive call to cp_parser_declarator
in the ptr-operator case and as an effect, delayed parsing of noexcept
didn't work as advertised.  The following change passes more than just
CP_PARSER_FLAGS_DELAY_NOEXCEPT but that doesn't seem to break anything.

I'm not passing member_p because I don't need it and because it breaks
a few tests.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches?

	PR c++/100752

gcc/cp/ChangeLog:

	* parser.c (cp_parser_declarator): Pass flags down to
	cp_parser_declarator.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/noexcept69.C: New test.
---
 gcc/cp/parser.c                         |  3 +--
 gcc/testsuite/g++.dg/cpp0x/noexcept69.C | 12 ++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept69.C


base-commit: c4574d23cb07340918793a5a98ae7bb2988b3791
-- 
2.31.1

Comments

Jason Merrill via Gcc-patches June 10, 2021, 7:09 p.m. | #1
On 6/8/21 8:25 PM, Marek Polacek wrote:
> We weren't passing 'flags' to the recursive call to cp_parser_declarator

> in the ptr-operator case and as an effect, delayed parsing of noexcept

> didn't work as advertised.  The following change passes more than just

> CP_PARSER_FLAGS_DELAY_NOEXCEPT but that doesn't seem to break anything.

> 

> I'm not passing member_p because I don't need it and because it breaks

> a few tests.

> 

> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches?

> 

> 	PR c++/100752

> 

> gcc/cp/ChangeLog:

> 

> 	* parser.c (cp_parser_declarator): Pass flags down to

> 	cp_parser_declarator.

> 

> gcc/testsuite/ChangeLog:

> 

> 	* g++.dg/cpp0x/noexcept69.C: New test.

> ---

>   gcc/cp/parser.c                         |  3 +--

>   gcc/testsuite/g++.dg/cpp0x/noexcept69.C | 12 ++++++++++++

>   2 files changed, 13 insertions(+), 2 deletions(-)

>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept69.C

> 

> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c

> index d59a829d0b9..5930990ec1c 100644

> --- a/gcc/cp/parser.c

> +++ b/gcc/cp/parser.c

> @@ -22066,8 +22066,7 @@ cp_parser_declarator (cp_parser* parser,

>   	cp_parser_parse_tentatively (parser);

>   

>         /* Parse the dependent declarator.  */

> -      declarator = cp_parser_declarator (parser, dcl_kind,

> -					 CP_PARSER_FLAGS_NONE,

> +      declarator = cp_parser_declarator (parser, dcl_kind, flags,

>   					 /*ctor_dtor_or_conv_p=*/NULL,

>   					 /*parenthesized_p=*/NULL,

>   					 /*member_p=*/false,


Should the other parameters also be passed down?  I'd think definitely 
member_p and static_p, not sure about ctor_dtor_or_conv_p and 
parenthesized_p.

> diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept69.C b/gcc/testsuite/g++.dg/cpp0x/noexcept69.C

> new file mode 100644

> index 00000000000..9b87ba0cafb

> --- /dev/null

> +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept69.C

> @@ -0,0 +1,12 @@

> +// PR c++/100752

> +// { dg-do compile { target c++11 } }

> +

> +struct S {

> +  void f() noexcept {}

> +  S &g() noexcept(noexcept(f())) { f(); return *this; }

> +};

> +

> +struct X {

> +  int& f() noexcept(noexcept(i));

> +  int i;

> +};

> 

> base-commit: c4574d23cb07340918793a5a98ae7bb2988b3791

>
Jason Merrill via Gcc-patches June 10, 2021, 9:19 p.m. | #2
On Thu, Jun 10, 2021 at 03:09:29PM -0400, Jason Merrill wrote:
> On 6/8/21 8:25 PM, Marek Polacek wrote:

> > We weren't passing 'flags' to the recursive call to cp_parser_declarator

> > in the ptr-operator case and as an effect, delayed parsing of noexcept

> > didn't work as advertised.  The following change passes more than just

> > CP_PARSER_FLAGS_DELAY_NOEXCEPT but that doesn't seem to break anything.

> > 

> > I'm not passing member_p because I don't need it and because it breaks

> > a few tests.

> > 

> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches?

> > 

> > 	PR c++/100752

> > 

> > gcc/cp/ChangeLog:

> > 

> > 	* parser.c (cp_parser_declarator): Pass flags down to

> > 	cp_parser_declarator.

> > 

> > gcc/testsuite/ChangeLog:

> > 

> > 	* g++.dg/cpp0x/noexcept69.C: New test.

> > ---

> >   gcc/cp/parser.c                         |  3 +--

> >   gcc/testsuite/g++.dg/cpp0x/noexcept69.C | 12 ++++++++++++

> >   2 files changed, 13 insertions(+), 2 deletions(-)

> >   create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept69.C

> > 

> > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c

> > index d59a829d0b9..5930990ec1c 100644

> > --- a/gcc/cp/parser.c

> > +++ b/gcc/cp/parser.c

> > @@ -22066,8 +22066,7 @@ cp_parser_declarator (cp_parser* parser,

> >   	cp_parser_parse_tentatively (parser);

> >         /* Parse the dependent declarator.  */

> > -      declarator = cp_parser_declarator (parser, dcl_kind,

> > -					 CP_PARSER_FLAGS_NONE,

> > +      declarator = cp_parser_declarator (parser, dcl_kind, flags,

> >   					 /*ctor_dtor_or_conv_p=*/NULL,

> >   					 /*parenthesized_p=*/NULL,

> >   					 /*member_p=*/false,

> 

> Should the other parameters also be passed down?  I'd think definitely

> member_p and static_p, not sure about ctor_dtor_or_conv_p and

> parenthesized_p.


Hmm, as I mentioned in the patch description, I tried, but passing member_p
broke a few tests and since it's not needed for this fix I gave up
investigating why.  I could look into it if you're curious :).
 
Marek
Jason Merrill via Gcc-patches June 11, 2021, 2:31 a.m. | #3
On 6/10/21 5:19 PM, Marek Polacek wrote:
> On Thu, Jun 10, 2021 at 03:09:29PM -0400, Jason Merrill wrote:

>> On 6/8/21 8:25 PM, Marek Polacek wrote:

>>> We weren't passing 'flags' to the recursive call to cp_parser_declarator

>>> in the ptr-operator case and as an effect, delayed parsing of noexcept

>>> didn't work as advertised.  The following change passes more than just

>>> CP_PARSER_FLAGS_DELAY_NOEXCEPT but that doesn't seem to break anything.

>>>

>>> I'm not passing member_p because I don't need it and because it breaks

>>> a few tests.

>>>

>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches?

>>>

>>> 	PR c++/100752

>>>

>>> gcc/cp/ChangeLog:

>>>

>>> 	* parser.c (cp_parser_declarator): Pass flags down to

>>> 	cp_parser_declarator.

>>>

>>> gcc/testsuite/ChangeLog:

>>>

>>> 	* g++.dg/cpp0x/noexcept69.C: New test.

>>> ---

>>>    gcc/cp/parser.c                         |  3 +--

>>>    gcc/testsuite/g++.dg/cpp0x/noexcept69.C | 12 ++++++++++++

>>>    2 files changed, 13 insertions(+), 2 deletions(-)

>>>    create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept69.C

>>>

>>> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c

>>> index d59a829d0b9..5930990ec1c 100644

>>> --- a/gcc/cp/parser.c

>>> +++ b/gcc/cp/parser.c

>>> @@ -22066,8 +22066,7 @@ cp_parser_declarator (cp_parser* parser,

>>>    	cp_parser_parse_tentatively (parser);

>>>          /* Parse the dependent declarator.  */

>>> -      declarator = cp_parser_declarator (parser, dcl_kind,

>>> -					 CP_PARSER_FLAGS_NONE,

>>> +      declarator = cp_parser_declarator (parser, dcl_kind, flags,

>>>    					 /*ctor_dtor_or_conv_p=*/NULL,

>>>    					 /*parenthesized_p=*/NULL,

>>>    					 /*member_p=*/false,

>>

>> Should the other parameters also be passed down?  I'd think definitely

>> member_p and static_p, not sure about ctor_dtor_or_conv_p and

>> parenthesized_p.

> 

> Hmm, as I mentioned in the patch description, I tried, but passing member_p

> broke a few tests and since it's not needed for this fix I gave up

> investigating why.  I could look into it if you're curious :).


Please.

Jason

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d59a829d0b9..5930990ec1c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -22066,8 +22066,7 @@  cp_parser_declarator (cp_parser* parser,
 	cp_parser_parse_tentatively (parser);
 
       /* Parse the dependent declarator.  */
-      declarator = cp_parser_declarator (parser, dcl_kind,
-					 CP_PARSER_FLAGS_NONE,
+      declarator = cp_parser_declarator (parser, dcl_kind, flags,
 					 /*ctor_dtor_or_conv_p=*/NULL,
 					 /*parenthesized_p=*/NULL,
 					 /*member_p=*/false,
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept69.C b/gcc/testsuite/g++.dg/cpp0x/noexcept69.C
new file mode 100644
index 00000000000..9b87ba0cafb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept69.C
@@ -0,0 +1,12 @@ 
+// PR c++/100752
+// { dg-do compile { target c++11 } }
+
+struct S {
+  void f() noexcept {}
+  S &g() noexcept(noexcept(f())) { f(); return *this; }
+};
+
+struct X {
+  int& f() noexcept(noexcept(i));
+  int i;
+};