* [PATCH] Fix parser to recognize operator?:
@ 2019-10-11 14:14 Matthias Kretz
2019-10-11 14:17 ` Marek Polacek
0 siblings, 1 reply; 7+ messages in thread
From: Matthias Kretz @ 2019-10-11 14:14 UTC (permalink / raw)
To: gcc-patches
This is a minor bugfix for improved error reporting. Overloading ?: is just as
disallowed as it is without this change.
2019-10-11 Matthias Kretz <m.kretz@gsi.de>
* gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
attempt to overload the conditional operator. Then
grok_op_properties can print its useful "ISO C++ prohibits
overloading operator ?:" message instead of the cryptic error
message about a missing type-specifier before '?' token.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3ee8da7db94..73385cb3dcb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
start_loc)
op = COMPONENT_REF;
break;
+ case CPP_QUERY:
+ op = COND_EXPR;
+ /* Consume the `?'. */
+ cp_lexer_consume_token (parser->lexer);
+ /* Look for the matching `:'. */
+ cp_parser_require (parser, CPP_COLON, RT_COLON);
+ consumed = true;
+ break;
+
case CPP_OPEN_PAREN:
{
/* Consume the `('. */
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix parser to recognize operator?:
2019-10-11 14:14 [PATCH] Fix parser to recognize operator?: Matthias Kretz
@ 2019-10-11 14:17 ` Marek Polacek
2019-10-14 8:29 ` Matthias Kretz
2019-10-14 10:35 ` Matthias Kretz
0 siblings, 2 replies; 7+ messages in thread
From: Marek Polacek @ 2019-10-11 14:17 UTC (permalink / raw)
To: Matthias Kretz; +Cc: gcc-patches
On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> This is a minor bugfix for improved error reporting. Overloading ?: is just as
> disallowed as it is without this change.
Thanks. Can you provide a testcase that shows why this change makes sense?
That testcase then should be part of the patch submission.
> 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
>
> * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> attempt to overload the conditional operator. Then
> grok_op_properties can print its useful "ISO C++ prohibits
> overloading operator ?:" message instead of the cryptic error
> message about a missing type-specifier before '?' token.
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 3ee8da7db94..73385cb3dcb 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> start_loc)
> op = COMPONENT_REF;
> break;
>
> + case CPP_QUERY:
> + op = COND_EXPR;
> + /* Consume the `?'. */
> + cp_lexer_consume_token (parser->lexer);
> + /* Look for the matching `:'. */
> + cp_parser_require (parser, CPP_COLON, RT_COLON);
> + consumed = true;
> + break;
> +
> case CPP_OPEN_PAREN:
> {
> /* Consume the `('. */
--
Marek Polacek ⢠Red Hat, Inc. ⢠300 A St, Boston, MA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix parser to recognize operator?:
2019-10-11 14:17 ` Marek Polacek
@ 2019-10-14 8:29 ` Matthias Kretz
2019-10-14 10:35 ` Matthias Kretz
1 sibling, 0 replies; 7+ messages in thread
From: Matthias Kretz @ 2019-10-14 8:29 UTC (permalink / raw)
To: Marek Polacek; +Cc: gcc-patches
On Freitag, 11. Oktober 2019 16:17:09 CEST Marek Polacek wrote:
> On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> > This is a minor bugfix for improved error reporting. Overloading ?: is
> > just as disallowed as it is without this change.
>
> Thanks. Can you provide a testcase that shows why this change makes sense?
> That testcase then should be part of the patch submission.
I can. Most (all?) testcases reference a PR. Should I open one?
>
> > 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
> >
> > * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> >
> > attempt to overload the conditional operator. Then
> > grok_op_properties can print its useful "ISO C++ prohibits
> > overloading operator ?:" message instead of the cryptic error
> > message about a missing type-specifier before '?' token.
> >
> > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> > index 3ee8da7db94..73385cb3dcb 100644
> > --- a/gcc/cp/parser.c
> > +++ b/gcc/cp/parser.c
> > @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> > start_loc)
> >
> > op = COMPONENT_REF;
> > break;
> >
> > + case CPP_QUERY:
> > + op = COND_EXPR;
> > + /* Consume the `?'. */
> > + cp_lexer_consume_token (parser->lexer);
> > + /* Look for the matching `:'. */
> > + cp_parser_require (parser, CPP_COLON, RT_COLON);
> > + consumed = true;
> > + break;
> > +
> >
> > case CPP_OPEN_PAREN:
> > {
> >
> > /* Consume the `('. */
>
> --
> Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix parser to recognize operator?:
2019-10-11 14:17 ` Marek Polacek
2019-10-14 8:29 ` Matthias Kretz
@ 2019-10-14 10:35 ` Matthias Kretz
2019-10-24 9:12 ` Dr. Matthias Kretz
` (2 more replies)
1 sibling, 3 replies; 7+ messages in thread
From: Matthias Kretz @ 2019-10-14 10:35 UTC (permalink / raw)
To: gcc-patches
This time with testcase. Is the subdir for the test ok?
gcc/ChangeLog:
2019-10-11 Matthias Kretz <m.kretz@gsi.de>
* gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
attempt to overload the conditional operator. Then
grok_op_properties can print its useful "ISO C++ prohibits
overloading operator ?:" message instead of the cryptic error
message about a missing type-specifier before '?' token.
gcc/testsuite/ChangeLog:
2019-10-14 Matthias Kretz <m.kretz@gsi.de>
* testsuite/g++.dg/parse/operator9.C: New test verifying the
correct error message is printed.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3ee8da7db94..73385cb3dcb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
start_loc)
op = COMPONENT_REF;
break;
+ case CPP_QUERY:
+ op = COND_EXPR;
+ /* Consume the `?'. */
+ cp_lexer_consume_token (parser->lexer);
+ /* Look for the matching `:'. */
+ cp_parser_require (parser, CPP_COLON, RT_COLON);
+ consumed = true;
+ break;
+
case CPP_OPEN_PAREN:
{
/* Consume the `('. */
diff --git a/gcc/testsuite/g++.dg/parse/operator9.C b/gcc/testsuite/g++.dg/
parse/operator9.C
new file mode 100644
index 00000000000..d66355afab5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/operator9.C
@@ -0,0 +1,5 @@
+// { dg-do compile }
+
+struct A {};
+struct B {};
+int operator?:(bool, A, B); // { dg-error "prohibits overloading" }
On Freitag, 11. Oktober 2019 16:17:09 CEST you wrote:
> On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> > This is a minor bugfix for improved error reporting. Overloading ?: is
> > just as disallowed as it is without this change.
>
> Thanks. Can you provide a testcase that shows why this change makes sense?
> That testcase then should be part of the patch submission.
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix parser to recognize operator?:
2019-10-14 10:35 ` Matthias Kretz
@ 2019-10-24 9:12 ` Dr. Matthias Kretz
2019-11-06 14:44 ` Ping2: " Matthias Kretz
2019-11-06 16:07 ` Jason Merrill
2 siblings, 0 replies; 7+ messages in thread
From: Dr. Matthias Kretz @ 2019-10-24 9:12 UTC (permalink / raw)
To: gcc-patches
ping
On Montag, 14. Oktober 2019 12:27:11 CEST Matthias Kretz wrote:
> This time with testcase. Is the subdir for the test ok?
>
> gcc/ChangeLog:
>
> 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
>
> * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> attempt to overload the conditional operator. Then
> grok_op_properties can print its useful "ISO C++ prohibits
> overloading operator ?:" message instead of the cryptic error
> message about a missing type-specifier before '?' token.
>
> gcc/testsuite/ChangeLog:
>
> 2019-10-14 Matthias Kretz <m.kretz@gsi.de>
> * testsuite/g++.dg/parse/operator9.C: New test verifying the
> correct error message is printed.
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 3ee8da7db94..73385cb3dcb 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> start_loc)
> op = COMPONENT_REF;
> break;
>
> + case CPP_QUERY:
> + op = COND_EXPR;
> + /* Consume the `?'. */
> + cp_lexer_consume_token (parser->lexer);
> + /* Look for the matching `:'. */
> + cp_parser_require (parser, CPP_COLON, RT_COLON);
> + consumed = true;
> + break;
> +
> case CPP_OPEN_PAREN:
> {
> /* Consume the `('. */
> diff --git a/gcc/testsuite/g++.dg/parse/operator9.C b/gcc/testsuite/g++.dg/
> parse/operator9.C
> new file mode 100644
> index 00000000000..d66355afab5
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/operator9.C
> @@ -0,0 +1,5 @@
> +// { dg-do compile }
> +
> +struct A {};
> +struct B {};
> +int operator?:(bool, A, B); // { dg-error "prohibits overloading" }
>
> On Freitag, 11. Oktober 2019 16:17:09 CEST you wrote:
> > On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> > > This is a minor bugfix for improved error reporting. Overloading ?: is
> > > just as disallowed as it is without this change.
> >
> > Thanks. Can you provide a testcase that shows why this change makes
> > sense?
> > That testcase then should be part of the patch submission.
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
^ permalink raw reply [flat|nested] 7+ messages in thread
* Ping2: [PATCH] Fix parser to recognize operator?:
2019-10-14 10:35 ` Matthias Kretz
2019-10-24 9:12 ` Dr. Matthias Kretz
@ 2019-11-06 14:44 ` Matthias Kretz
2019-11-06 16:07 ` Jason Merrill
2 siblings, 0 replies; 7+ messages in thread
From: Matthias Kretz @ 2019-11-06 14:44 UTC (permalink / raw)
To: gcc-patches
ping2
On Montag, 14. Oktober 2019 12:27:11 CET Matthias Kretz wrote:
> This time with testcase. Is the subdir for the test ok?
>
> gcc/ChangeLog:
>
> 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
>
> * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> attempt to overload the conditional operator. Then
> grok_op_properties can print its useful "ISO C++ prohibits
> overloading operator ?:" message instead of the cryptic error
> message about a missing type-specifier before '?' token.
>
> gcc/testsuite/ChangeLog:
>
> 2019-10-14 Matthias Kretz <m.kretz@gsi.de>
> * testsuite/g++.dg/parse/operator9.C: New test verifying the
> correct error message is printed.
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 3ee8da7db94..73385cb3dcb 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> start_loc)
> op = COMPONENT_REF;
> break;
>
> + case CPP_QUERY:
> + op = COND_EXPR;
> + /* Consume the `?'. */
> + cp_lexer_consume_token (parser->lexer);
> + /* Look for the matching `:'. */
> + cp_parser_require (parser, CPP_COLON, RT_COLON);
> + consumed = true;
> + break;
> +
> case CPP_OPEN_PAREN:
> {
> /* Consume the `('. */
> diff --git a/gcc/testsuite/g++.dg/parse/operator9.C b/gcc/testsuite/g++.dg/
> parse/operator9.C
> new file mode 100644
> index 00000000000..d66355afab5
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/operator9.C
> @@ -0,0 +1,5 @@
> +// { dg-do compile }
> +
> +struct A {};
> +struct B {};
> +int operator?:(bool, A, B); // { dg-error "prohibits overloading" }
>
> On Freitag, 11. Oktober 2019 16:17:09 CEST you wrote:
> > On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> > > This is a minor bugfix for improved error reporting. Overloading ?: is
> > > just as disallowed as it is without this change.
> >
> > Thanks. Can you provide a testcase that shows why this change makes
> > sense?
> > That testcase then should be part of the patch submission.
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix parser to recognize operator?:
2019-10-14 10:35 ` Matthias Kretz
2019-10-24 9:12 ` Dr. Matthias Kretz
2019-11-06 14:44 ` Ping2: " Matthias Kretz
@ 2019-11-06 16:07 ` Jason Merrill
2 siblings, 0 replies; 7+ messages in thread
From: Jason Merrill @ 2019-11-06 16:07 UTC (permalink / raw)
To: Matthias Kretz, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]
On 10/14/19 11:27 AM, Matthias Kretz wrote:
> This time with testcase. Is the subdir for the test ok?
Yes.
> gcc/ChangeLog:
>
> 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
>
> * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> attempt to overload the conditional operator. Then
> grok_op_properties can print its useful "ISO C++ prohibits
> overloading operator ?:" message instead of the cryptic error
> message about a missing type-specifier before '?' token.
The first sentence is enough for a ChangeLog; the second should be an
explanatory comment above the ChangeLog entries.
Also, this entry belongs in gcc/cp/ChangeLog.
> +++ b/gcc/cp/parser.c
> @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> start_loc)
Word wrap broke the patch here. Feel free to send patches as
attachments if it's hard to suppress word wrap in your mailer (as it is
in mine).
I also saw an additional failure in the testsuite:
> FAIL: g++.old-deja/g++.jason/operator.C -std=gnu++2a (test for
errors, line 8)
> FAIL: g++.old-deja/g++.jason/operator.C -std=gnu++2a (test for
excess errors)
Here's what I'm applying:
Jason
[-- Attachment #2: opcond.diff --]
[-- Type: text/x-patch, Size: 2843 bytes --]
commit c3e97f573b6e29324ef72ded63e0307cec8d2ce2
Author: Jason Merrill <jason@redhat.com>
Date: Tue Nov 5 17:31:44 2019 +0000
Fix parser to recognize operator?:
This change lets grok_op_properties print its useful "ISO C++ prohibits
overloading operator ?:" message instead of the cryptic error message about
a missing type-specifier before '?' token.
2019-11-06 Matthias Kretz <m.kretz@gsi.de>
* parser.c (cp_parser_operator): Parse operator?: as an
attempt to overload the conditional operator.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index cbbf946d32c..b17e0336e1c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15542,6 +15542,15 @@ cp_parser_operator (cp_parser* parser, location_t start_loc)
op = COMPONENT_REF;
break;
+ case CPP_QUERY:
+ op = COND_EXPR;
+ /* Consume the `?'. */
+ cp_lexer_consume_token (parser->lexer);
+ /* Look for the matching `:'. */
+ cp_parser_require (parser, CPP_COLON, RT_COLON);
+ consumed = true;
+ break;
+
case CPP_OPEN_PAREN:
{
/* Consume the `('. */
diff --git a/gcc/testsuite/g++.dg/parse/operator9.C b/gcc/testsuite/g++.dg/parse/operator9.C
new file mode 100644
index 00000000000..d66355afab5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/operator9.C
@@ -0,0 +1,5 @@
+// { dg-do compile }
+
+struct A {};
+struct B {};
+int operator?:(bool, A, B); // { dg-error "prohibits overloading" }
diff --git a/gcc/testsuite/g++.old-deja/g++.jason/operator.C b/gcc/testsuite/g++.old-deja/g++.jason/operator.C
index c2fc212cef0..69a41cf2448 100644
--- a/gcc/testsuite/g++.old-deja/g++.jason/operator.C
+++ b/gcc/testsuite/g++.old-deja/g++.jason/operator.C
@@ -5,7 +5,7 @@
typedef __SIZE_TYPE__ size_t;
struct A {
- int operator?:(int a, int b); // { dg-error "expected type-specifier" }
+ int operator?:(int a, int b); // { dg-error "prohibits overloading" }
static int operator()(int a); // { dg-error "14:.static int A::operator\\(\\)\\(int\\). must be a nonstatic member function" }
static int operator+(A,A); // { dg-error "14:.static int A::operator\\+\\(A, A\\). must be either a non-static member function or a non-member function" }
int operator+(int a, int b = 1); // { dg-error "7:.int A::operator\\+\\(int, int\\). must have either zero or one argument" }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d0b47f7c562..e60a45b869e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-06 Matthias Kretz <m.kretz@gsi.de>
+
+ * parser.c (cp_parser_operator): Parse operator?: as an
+ attempt to overload the conditional operator.
+
2019-11-05 Jason Merrill <jason@redhat.com>
Implement C++20 operator<=>.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-11-06 16:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 14:14 [PATCH] Fix parser to recognize operator?: Matthias Kretz
2019-10-11 14:17 ` Marek Polacek
2019-10-14 8:29 ` Matthias Kretz
2019-10-14 10:35 ` Matthias Kretz
2019-10-24 9:12 ` Dr. Matthias Kretz
2019-11-06 14:44 ` Ping2: " Matthias Kretz
2019-11-06 16:07 ` Jason Merrill
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).