summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-09-07 14:35:10 +0000
committerDouglas Gregor <dgregor@apple.com>2010-09-07 14:35:10 +0000
commit3465e26102ee483f5e6b2ca0062bda47c0c4a63d (patch)
tree9f75974cd3178889e6ac679314a9a4f74b784845
parent6282336772857d7da63a5947e6a070916d95865d (diff)
downloadbcm5719-llvm-3465e26102ee483f5e6b2ca0062bda47c0c4a63d.tar.gz
bcm5719-llvm-3465e26102ee483f5e6b2ca0062bda47c0c4a63d.zip
Improve diagnostic and recovery when missing a comma between base or
member initializers in a C++ constructor. Fixes <rdar://problem/7796492>. llvm-svn: 113199
-rw-r--r--clang/include/clang/Basic/DiagnosticParseKinds.td3
-rw-r--r--clang/lib/Parse/ParseDeclCXX.cpp6
-rw-r--r--clang/test/FixIt/fixit.cpp9
3 files changed, 18 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 646fd0d1bfb..50e98706f51 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -364,6 +364,9 @@ def err_default_template_template_parameter_not_template : Error<
"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">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index b277156a0d0..6a63986f4a5 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1735,6 +1735,12 @@ void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) {
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);
diff --git a/clang/test/FixIt/fixit.cpp b/clang/test/FixIt/fixit.cpp
index b9282c4d948..5a281323970 100644
--- a/clang/test/FixIt/fixit.cpp
+++ b/clang/test/FixIt/fixit.cpp
@@ -51,3 +51,12 @@ namespace rdar7853795 {
}
};
}
+
+namespace rdar7796492 {
+ class A { int x, y; A(); };
+
+ A::A()
+ : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}}
+ }
+
+}
OpenPOWER on IntegriCloud