[cfe-commits] r113199 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDeclCXX.cpp test/FixIt/fixit.cpp
Douglas Gregor
dgregor at apple.com
Tue Sep 7 07:35:10 PDT 2010
Author: dgregor
Date: Tue Sep 7 09:35:10 2010
New Revision: 113199
URL: http://llvm.org/viewvc/llvm-project?rev=113199&view=rev
Log:
Improve diagnostic and recovery when missing a comma between base or
member initializers in a C++ constructor. Fixes <rdar://problem/7796492>.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/test/FixIt/fixit.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=113199&r1=113198&r2=113199&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Sep 7 09:35:10 2010
@@ -364,6 +364,9 @@
"default template argument for a template template parameter must be a class "
"template">;
+def err_ctor_init_missing_comma : Error<
+ "missing ',' between base or member initializers">;
+
// C++ declarations
def err_friend_decl_defines_class : Error<
"cannot define a type in a friend declaration">;
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=113199&r1=113198&r2=113199&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Sep 7 09:35:10 2010
@@ -1735,6 +1735,12 @@
ConsumeToken();
else if (Tok.is(tok::l_brace))
break;
+ // If the next token looks like a base or member initializer, assume that
+ // we're just missing a comma.
+ else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon))
+ Diag(Tok.getLocation(), diag::err_ctor_init_missing_comma)
+ << FixItHint::CreateInsertion(PP.getLocForEndOfToken(PrevTokLocation),
+ ", ");
else {
// Skip over garbage, until we get to '{'. Don't eat the '{'.
Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma);
Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=113199&r1=113198&r2=113199&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Tue Sep 7 09:35:10 2010
@@ -51,3 +51,12 @@
}
};
}
+
+namespace rdar7796492 {
+ class A { int x, y; A(); };
+
+ A::A()
+ : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}}
+ }
+
+}
More information about the cfe-commits
mailing list