[PATCH] Add context to "expected unqualified-id" message
Richard Trieu
rtrieu at google.com
Mon Jun 24 19:12:35 PDT 2013
Instead of adding a new note, move the error message to point to the end of the currently parsed declarator.
http://llvm-reviews.chandlerc.com/D1032
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1032?vs=2548&id=2550#toc
Files:
test/Parser/cxx-decl.cpp
include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
Index: test/Parser/cxx-decl.cpp
===================================================================
--- test/Parser/cxx-decl.cpp
+++ test/Parser/cxx-decl.cpp
@@ -187,6 +187,21 @@
// Ensure we produce at least some diagnostic for attributes in C++98.
[[]] struct S; // expected-error 2{{}}
+namespace test7 {
+ struct Foo {
+ int a();
+ int b();
+ };
+
+ int Foo::
+ // Comment!
+ a() {}
+
+
+ int Foo:: // expected-error {{expected unqualified-id}}
+ // Comment!
+}
+
// PR8380
extern "" // expected-error {{unknown linkage language}}
test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \
Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -450,6 +450,7 @@
"cannot use %select{dot|arrow}0 operator on a type">;
def err_expected_unqualified_id : Error<
"expected %select{identifier|unqualified-id}0">;
+def note_after_here : Note<"after here">;
def err_func_def_no_params : Error<
"function definition does not declare parameters">;
def err_expected_lparen_after_type : Error<
Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -4737,8 +4737,15 @@
else if (getLangOpts().CPlusPlus) {
if (Tok.is(tok::period) || Tok.is(tok::arrow))
Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
- else
- Diag(Tok, diag::err_expected_unqualified_id) << getLangOpts().CPlusPlus;
+ else {
+ SourceLocation Loc = D.getCXXScopeSpec().getEndLoc();
+ if (Tok.isAtStartOfLine() && Loc.isValid())
+ Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
+ << getLangOpts().CPlusPlus;
+ else
+ Diag(Tok, diag::err_expected_unqualified_id)
+ << getLangOpts().CPlusPlus;
+ }
} else
Diag(Tok, diag::err_expected_ident_lparen);
D.SetIdentifier(0, Tok.getLocation());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1032.2.patch
Type: text/x-patch
Size: 2139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130624/314e5315/attachment.bin>
More information about the cfe-commits
mailing list