-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 10326 |
| Version | unspecified |
| OS | All |
Extended Description
The following program is clearly invalid, but I think we could do better diagnosing it:
% cat x.cc
struct S {
S* foo(int) { return this; }
};
S* test() {
return new S()->foo(42);
}
% ./bin/clang -fsyntax-only x.cc
x.cc:6:17: error: expected ';' after return statement
return new S()->foo(42);
^
;
1 error generated.
It seems like it would be better to say in the error that the new operator has lower precedence than '->', and thus the new expression must be explicitly grouped. Then we could recover and continue parsing the rest of the expression as if that grouping had been performed. This seems reasonable to do for most of the postfix expressions which form a suffix but could not reasonable be part of a new-type-id: '->', '--', '++', and even '(...)' when the parentheses are not parsed as part of the new-initializer.