[cfe-commits] r124860 - in /cfe/trunk: lib/Parse/Parser.cpp test/Parser/cxx-in-c.c

Douglas Gregor dgregor at apple.com
Fri Feb 4 03:57:16 PST 2011


Author: dgregor
Date: Fri Feb  4 05:57:16 2011
New Revision: 124860

URL: http://llvm.org/viewvc/llvm-project?rev=124860&view=rev
Log:
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.

Added:
    cfe/trunk/test/Parser/cxx-in-c.c   (with props)
Modified:
    cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=124860&r1=124859&r2=124860&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Fri Feb  4 05:57:16 2011
@@ -739,8 +739,9 @@
 
   // 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 '{'.

Added: cfe/trunk/test/Parser/cxx-in-c.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-in-c.c?rev=124860&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-in-c.c (added)
+++ cfe/trunk/test/Parser/cxx-in-c.c Fri Feb  4 05:57:16 2011
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify
+
+// PR9137
+void f0(int x) : {};
+void f1(int x) try {};

Propchange: cfe/trunk/test/Parser/cxx-in-c.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Parser/cxx-in-c.c
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Parser/cxx-in-c.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list