Commit 6394a341 by Matthias Kretz Committed by Jason Merrill

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.

From-SVN: r277887
parent 4b205bf8
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> 2019-11-05 Jason Merrill <jason@redhat.com>
Implement C++20 operator<=>. Implement C++20 operator<=>.
......
...@@ -15542,6 +15542,15 @@ cp_parser_operator (cp_parser* parser, location_t start_loc) ...@@ -15542,6 +15542,15 @@ cp_parser_operator (cp_parser* parser, location_t start_loc)
op = COMPONENT_REF; op = COMPONENT_REF;
break; 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: case CPP_OPEN_PAREN:
{ {
/* Consume the `('. */ /* Consume the `('. */
// { dg-do compile }
struct A {};
struct B {};
int operator?:(bool, A, B); // { dg-error "prohibits overloading" }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
typedef __SIZE_TYPE__ size_t; typedef __SIZE_TYPE__ size_t;
struct A { 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()(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" } 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" } int operator+(int a, int b = 1); // { dg-error "7:.int A::operator\\+\\(int, int\\). must have either zero or one argument" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment