"expected ';' after expression")
DIAG(err_expected_semi_after_method_proto, ERROR,
"expected ';' after method prototype")
+DIAG(err_expected_semi_after_static_assert, ERROR,
+ "expected ';' after static_assert")
DIAG(err_expected_semi_for, ERROR,
"expected ';' in 'for' statement specifier")
DIAG(err_expected_colon_after, ERROR,
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method) {
}
+ virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation LParenLoc,
+ ExprArg AssertExpr,
+ SourceLocation CommaLoc,
+ ExprArg AssertMessageExpr,
+ SourceLocation RParenLoc) {
+ return 0;
+ }
+
+
//===------------------------- C++ Expressions --------------------------===//
/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
DeclTy *ParseUsingDirectiveOrDeclaration(unsigned Context);
DeclTy *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc);
DeclTy *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc);
+ DeclTy *ParseStaticAssertDeclaration();
//===--------------------------------------------------------------------===//
// C++ 9: classes [class] and C structs/unions.
/// [C++] namespace-definition
/// [C++] using-directive
/// [C++] using-declaration [TODO]
+// [C++0x] static_assert-declaration
/// others... [FIXME]
///
Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) {
return ParseNamespace(Context);
case tok::kw_using:
return ParseUsingDirectiveOrDeclaration(Context);
+ case tok::kw_static_assert:
+ return ParseStaticAssertDeclaration();
default:
return ParseSimpleDeclaration(Context);
}
return 0;
}
+/// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion.
+///
+/// static_assert-declaration:
+/// static_assert ( constant-expression , string-literal ) ;
+///
+Parser::DeclTy *Parser::ParseStaticAssertDeclaration() {
+ assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration");
+ SourceLocation StaticAssertLoc = ConsumeToken();
+
+ if (Tok.isNot(tok::l_paren)) {
+ Diag(Tok, diag::err_expected_lparen);
+ return 0;
+ }
+
+ SourceLocation LParenLoc = ConsumeParen();
+
+ OwningExprResult AssertExpr(ParseConstantExpression());
+ if (AssertExpr.isInvalid()) {
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ if (Tok.isNot(tok::comma)) {
+ Diag(Tok, diag::err_expected_comma);
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ SourceLocation CommaLoc = ConsumeToken();
+
+ if (Tok.isNot(tok::string_literal)) {
+ Diag(Tok, diag::err_expected_string_literal);
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ OwningExprResult AssertMessage(ParseStringLiteralExpression());
+ if (AssertMessage.isInvalid())
+ return 0;
+
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert);
+
+ return Actions.ActOnStaticAssertDeclaration(LParenLoc, move(AssertExpr),
+ CommaLoc, move(AssertMessage),
+ RParenLoc);
+}
+
/// ParseClassName - Parse a C++ class-name, which names a class. Note
/// that we only check that the result names a type; semantic analysis
/// will need to verify that the type names a class. The result is
/// function-definition ';'[opt]
/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO]
/// using-declaration [TODO]
-/// [C++0x] static_assert-declaration [TODO]
+/// [C++0x] static_assert-declaration
/// template-declaration [TODO]
/// [GNU] '__extension__' member-declaration
///
/// '=' constant-expression
///
Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
+ // static_assert-declaration
+ if (Tok.is(tok::kw_static_assert))
+ return ParseStaticAssertDeclaration();
+
// Handle: member-declaration ::= '__extension__' member-declaration
if (Tok.is(tok::kw___extension__)) {
// __extension__ silences extension warnings in the subexpression.
/// namespace-alias-definition
/// using-declaration
/// using-directive
-/// [C++0x] static_assert-declaration [TODO]
+/// [C++0x] static_assert-declaration
///
/// asm-definition:
/// 'asm' '(' string-literal ')' ';'
/// 'using' 'namespace' '::'[opt] nested-name-specifier[opt]
/// namespace-name ';'
///
-/// [C++0x] static_assert-declaration: [TODO]
-/// [C++0x] static_assert '(' constant-expression ',' string-literal ')' ';'
-///
bool Parser::isCXXDeclarationStatement() {
switch (Tok.getKind()) {
// asm-definition
// using-directive
case tok::kw_using:
return true;
+ case tok::kw_static_assert:
+ // static_assert-declaration
+ return true;
default:
// simple-declaration
return isCXXSimpleDeclaration();
case tok::kw_typedef:
case tok::kw_template:
case tok::kw_export: // As in 'export template'
+ case tok::kw_static_assert:
// A function definition cannot start with a these keywords.
return ParseDeclaration(Declarator::FileContext);
default: