Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Parser] Improve diagnostic and error recovery when C++ keywords are …
…used as identifiers. Summary: Previously, clang emitted a less-usefull diagnostic and didnt recover well when the keywords is used as identifier in function paramter. ``` void foo(int case, int x); // previously we drop all parameters after `int case`. ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77633
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s | ||
|
||
|
||
int foo1(int case, int throw, int y) { // expected-error {{invalid parameter name: 'case' is a keyword}} \ | ||
expected-error {{invalid}} | ||
// Trailing parameters should be recovered. | ||
y = 1; | ||
} | ||
|
||
int foo2(int case = 1); // expected-error {{invalid parameter}} | ||
int foo3(int const); // ok: without parameter name. | ||
// ok: override has special meaning when used after method functions. it can be | ||
// used as name. | ||
int foo4(int override); | ||
int foo5(int x const); // expected-error {{expected ')'}} expected-note {{to match this '('}} | ||
// FIXME: bad recovery on the case below, "invalid parameter" is desired, the | ||
// followon diagnostics should be suppressed. | ||
int foo6(int case __attribute((weak))); // expected-error {{invalid parameter}} \ | ||
// expected-error {{expected ')'}} expected-note {{to match this '('}} | ||
|
||
void test() { | ||
// FIXME: we shoud improve the dianostics for the following cases. | ||
int case; // expected-error {{expected unqualified-id}} | ||
struct X { | ||
int case; // expected-error {{expected member name or ';'}} | ||
}; | ||
} |