From: Richard Smith Date: Tue, 13 Jan 2015 02:24:58 +0000 (+0000) Subject: If we don't find a matching ) for a ( in an exception specification, keep the tokens... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12421c320c160d193726f50f4d53f1457d0e905f;p=clang If we don't find a matching ) for a ( in an exception specification, keep the tokens around so we can diagnose an error rather than silently discarding them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225755 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 09239f467e..062b63e7fd 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -3149,15 +3149,10 @@ Parser::tryParseExceptionSpecification(bool Delayed, ExceptionSpecTokens->push_back(StartTok); // 'throw' or 'noexcept' ExceptionSpecTokens->push_back(Tok); // '(' SpecificationRange.setEnd(ConsumeParen()); // '(' - - if (!ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens, - /*StopAtSemi=*/true, - /*ConsumeFinalToken=*/true)) { - NoexceptExpr = 0; - delete ExceptionSpecTokens; - ExceptionSpecTokens = 0; - return IsNoexcept? EST_BasicNoexcept : EST_DynamicNone; - } + + ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens, + /*StopAtSemi=*/true, + /*ConsumeFinalToken=*/true); SpecificationRange.setEnd(Tok.getLocation()); // Add the 'stop' token. diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index b6eb1b46db..0e9a3b9d54 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -179,6 +179,14 @@ class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}} class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}} } +class BadExceptionSpec { + void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}} + void g() throw( // expected-note {{to match}} + int( // expected-note {{to match}} + ; // expected-error 2{{expected ')'}} expected-error {{unexpected end of exception specification}} + )); +}; + // PR11109 must appear at the end of the source file class pr11109r3 { // expected-note{{to match this '{'}} public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}