зеркало из https://github.com/microsoft/clang.git
C1X: implement static asserts
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129555 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
f111d93572
Коммит
c6eb44b321
|
@ -241,6 +241,8 @@ def err_unexected_colon_in_nested_name_spec : Error<
|
|||
"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<
|
||||
|
|
|
@ -240,6 +240,7 @@ KEYWORD(_Bool , KEYNOCXX)
|
|||
KEYWORD(_Complex , KEYALL)
|
||||
KEYWORD(_Generic , KEYALL)
|
||||
KEYWORD(_Imaginary , KEYALL)
|
||||
KEYWORD(_Static_assert , KEYALL)
|
||||
KEYWORD(__func__ , KEYALL)
|
||||
|
||||
// C++ 2.11p1: Keywords.
|
||||
|
|
|
@ -653,7 +653,7 @@ void Parser::DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs) {
|
|||
/// [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,
|
||||
|
@ -688,6 +688,7 @@ 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;
|
||||
|
@ -2923,6 +2924,9 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
|
|||
// typedef-name
|
||||
case tok::annot_typename:
|
||||
|
||||
// static_assert-declaration
|
||||
case tok::kw__Static_assert:
|
||||
|
||||
// GNU typeof support.
|
||||
case tok::kw_typeof:
|
||||
|
||||
|
|
|
@ -404,13 +404,21 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context,
|
|||
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)) {
|
||||
|
@ -1426,7 +1434,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -58,6 +58,7 @@ bool Parser::isCXXDeclarationStatement() {
|
|||
case tok::kw_using:
|
||||
// static_assert-declaration
|
||||
case tok::kw_static_assert:
|
||||
case tok::kw__Static_assert:
|
||||
return true;
|
||||
// simple-declaration
|
||||
default:
|
||||
|
|
|
@ -557,6 +557,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
|
|||
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;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// 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"}}
|
||||
}
|
Загрузка…
Ссылка в новой задаче