aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-04 11:57:16 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-04 11:57:16 +0000
commit758afbcc86ef15f8d433f5f87db1495e50effeb3 (patch)
treeb135045efd582c6d076ed8f7f9482fcb6c386251
parentcd9175d5013700b2827fc727fed2b53ea89be027 (diff)
Fix a crash-on-invalid where we were trying to parse C++ constructs in
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
-rw-r--r--lib/Parse/Parser.cpp5
-rw-r--r--test/Parser/cxx-in-c.c5
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 3327f7b5a9..4b2bd0d89c 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -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
index 0000000000..50212ad0b3
--- /dev/null
+++ b/test/Parser/cxx-in-c.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify
+
+// PR9137
+void f0(int x) : {};
+void f1(int x) try {};