aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Parse/Parser.h1
-rw-r--r--lib/Parse/ParseDecl.cpp12
-rw-r--r--lib/Parse/ParseDeclCXX.cpp33
-rw-r--r--test/Parser/cxx-exception-spec.cpp15
4 files changed, 58 insertions, 3 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index e505e4d9ca..47b1191818 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -492,6 +492,7 @@ private:
//===--------------------------------------------------------------------===//
// C++ 15: C++ Throw Expression
ExprResult ParseThrowExpression();
+ bool ParseExceptionSpecification();
//===--------------------------------------------------------------------===//
// C++ 2.13.5: C++ Boolean Literals
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 1b5a0a5e7a..eaf9f8b0f9 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1653,7 +1653,10 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
DeclSpec DS;
if (getLang().CPlusPlus) {
ParseTypeQualifierListOpt(DS);
- // FIXME: Parse exception-specification[opt].
+
+ // Parse exception-specification[opt].
+ if (Tok.is(tok::kw_throw))
+ ParseExceptionSpecification();
}
// Remember that we parsed a function type, and remember the attributes.
@@ -1783,11 +1786,14 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
// If we have the closing ')', eat it.
MatchRHSPunctuation(tok::r_paren, LParenLoc);
- // cv-qualifier-seq[opt].
DeclSpec DS;
if (getLang().CPlusPlus) {
+ // Parse cv-qualifier-seq[opt].
ParseTypeQualifierListOpt(DS);
- // FIXME: Parse exception-specification[opt].
+
+ // Parse exception-specification[opt].
+ if (Tok.is(tok::kw_throw))
+ ParseExceptionSpecification();
}
// Remember that we parsed a function type, and remember the attributes.
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 17f5763c1d..9e380c9036 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -760,3 +760,36 @@ Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) {
LParenLoc, &ArgExprs[0], ArgExprs.size(),
&CommaLocs[0], RParenLoc);
}
+
+/// ParseExceptionSpecification - Parse a C++ exception-specification
+/// (C++ [except.spec]).
+///
+/// exception-specification:
+/// 'throw' '(' type-id-list [opt] ')'
+///
+/// type-id-list:
+/// type-id
+/// type-id-list ',' type-id
+///
+bool Parser::ParseExceptionSpecification() {
+ assert(Tok.is(tok::kw_throw) && "expected throw");
+
+ SourceLocation ThrowLoc = ConsumeToken();
+
+ if (!Tok.is(tok::l_paren)) {
+ return Diag(Tok, diag::err_expected_lparen_after) << "throw";
+ }
+ SourceLocation LParenLoc = ConsumeParen();
+
+ // Parse the sequence of type-ids.
+ while (Tok.isNot(tok::r_paren)) {
+ ParseTypeName();
+ if (Tok.is(tok::comma))
+ ConsumeToken();
+ else
+ break;
+ }
+
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+ return false;
+}
diff --git a/test/Parser/cxx-exception-spec.cpp b/test/Parser/cxx-exception-spec.cpp
new file mode 100644
index 0000000000..47e9ffb50b
--- /dev/null
+++ b/test/Parser/cxx-exception-spec.cpp
@@ -0,0 +1,15 @@
+// RUN: clang -fsyntax-only %s
+
+struct X { };
+
+struct Y { };
+
+void f() throw() { }
+
+void g(int) throw(X) { }
+
+void h() throw(X, Y) { }
+
+class Class {
+ void foo() throw (X, Y) { }
+};