]> granicus.if.org Git - clang/commitdiff
Fix a crash-on-invalid where we were trying to parse C++ constructs in
authorDouglas Gregor <dgregor@apple.com>
Fri, 4 Feb 2011 11:57:16 +0000 (11:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 4 Feb 2011 11:57:16 +0000 (11:57 +0000)
C, then hitting an assertion because C code shouldn't try to parse
optional nested-name-specifiers. Fixes PR9137.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124860 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/Parser.cpp
test/Parser/cxx-in-c.c [new file with mode: 0644]

index 3327f7b5a90920cf7b1c79456f09f7408b113dc0..4b2bd0d89cff7f7eae2a9673355cbe05c4b6fab8 100644 (file)
@@ -739,8 +739,9 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
 
   // We should have either an opening brace or, in a C++ constructor,
   // we may have a colon.
-  if (Tok.isNot(tok::l_brace) && Tok.isNot(tok::colon) &&
-      Tok.isNot(tok::kw_try)) {
+  if (Tok.isNot(tok::l_brace) && 
+      (!getLang().CPlusPlus ||
+       (Tok.isNot(tok::colon) && Tok.isNot(tok::kw_try)))) {
     Diag(Tok, diag::err_expected_fn_body);
 
     // Skip over garbage, until we get to '{'.  Don't eat the '{'.
diff --git a/test/Parser/cxx-in-c.c b/test/Parser/cxx-in-c.c
new file mode 100644 (file)
index 0000000..50212ad
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify
+
+// PR9137
+void f0(int x) : {};
+void f1(int x) try {};