"unexpected ':' in nested name specifier">;
def err_bool_redeclaration : Error<
"redeclaration of C++ built-in type 'bool'">;
+def ext_c1x_static_assert : Extension<
+ "_Static_assert is a C1X-specific feature">;
/// Objective-C parser diagnostics
def err_expected_minus_or_plus : Error<
KEYWORD(_Complex , KEYALL)
KEYWORD(_Generic , KEYALL)
KEYWORD(_Imaginary , KEYALL)
+KEYWORD(_Static_assert , KEYALL)
KEYWORD(__func__ , KEYALL)
// C++ 2.11p1: Keywords.
/// [C++] namespace-definition
/// [C++] using-directive
/// [C++] using-declaration
-/// [C++0x] static_assert-declaration
+/// [C++0x/C1X] static_assert-declaration
/// others... [FIXME]
///
Parser::DeclGroupPtrTy Parser::ParseDeclaration(StmtVector &Stmts,
DeclEnd, attrs);
break;
case tok::kw_static_assert:
+ case tok::kw__Static_assert:
ProhibitAttributes(attrs);
SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
break;
// typedef-name
case tok::annot_typename:
+ // static_assert-declaration
+ case tok::kw__Static_assert:
+
// GNU typeof support.
case tok::kw_typeof:
IsTypeName, TypenameLoc);
}
-/// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion.
+/// ParseStaticAssertDeclaration - Parse C++0x or C1X static_assert-declaration.
///
-/// static_assert-declaration:
-/// static_assert ( constant-expression , string-literal ) ;
+/// [C++0x] static_assert-declaration:
+/// static_assert ( constant-expression , string-literal ) ;
+///
+/// [C1X] static_assert-declaration:
+/// _Static_assert ( constant-expression , string-literal ) ;
///
Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
- assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration");
+ assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) &&
+ "Not a static_assert declaration");
+
+ if (Tok.is(tok::kw__Static_assert) && !getLang().C1X)
+ Diag(Tok, diag::ext_c1x_static_assert);
+
SourceLocation StaticAssertLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren)) {
}
// static_assert-declaration
- if (Tok.is(tok::kw_static_assert)) {
+ if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) {
// FIXME: Check for templates
SourceLocation DeclEnd;
ParseStaticAssertDeclaration(DeclEnd);
case tok::kw_using:
// static_assert-declaration
case tok::kw_static_assert:
+ case tok::kw__Static_assert:
return true;
// simple-declaration
default:
case tok::kw_template:
case tok::kw_export: // As in 'export template'
case tok::kw_static_assert:
+ case tok::kw__Static_assert:
// A function definition cannot start with a these keywords.
{
SourceLocation DeclEnd;
--- /dev/null
+// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
+
+_Static_assert("foo", "string is nonzero"); // expected-error {{static_assert expression is not an integral constant expression}}
+
+_Static_assert(1, "1 is nonzero");
+_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+
+void foo(void) {
+ _Static_assert(1, "1 is nonzero");
+ _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+}