diff options
-rw-r--r-- | Driver/PrintParserCallbacks.cpp | 3 | ||||
-rw-r--r-- | include/clang/AST/DeclCXX.h | 12 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 3 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 19 | ||||
-rw-r--r-- | test/SemaCXX/static-assert.cpp | 10 |
8 files changed, 43 insertions, 18 deletions
diff --git a/Driver/PrintParserCallbacks.cpp b/Driver/PrintParserCallbacks.cpp index f9399e2e1e..b123505bf8 100644 --- a/Driver/PrintParserCallbacks.cpp +++ b/Driver/PrintParserCallbacks.cpp @@ -724,8 +724,7 @@ namespace { virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg AssertExpr, - ExprArg AssertMessageExpr, - SourceLocation RParenLoc) { + ExprArg AssertMessageExpr) { llvm::cout << __FUNCTION__ << "\n"; return 0; } diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 43a91b47c7..740d37f30b 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -887,20 +887,24 @@ public: }; class StaticAssertDecl : public Decl { - SourceLocation AssertLoc; - Expr *AssertExpr; StringLiteral *Message; - + StaticAssertDecl(DeclContext *DC, SourceLocation L, Expr *assertexpr, StringLiteral *message) - : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } + : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { } public: static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, Expr *AssertExpr, StringLiteral *Message); + Expr *getAssertExpr() { return AssertExpr; } + const Expr *getAssertExpr() const { return AssertExpr; } + + StringLiteral *getMessage() { return Message; } + const StringLiteral *getMessage() const { return Message; } + virtual ~StaticAssertDecl(); virtual void Destroy(ASTContext& C); diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index f33918eae8..355eed1f91 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -893,8 +893,7 @@ public: /// ActOnStaticAssertDeclaration - Parse a C++0x static_assert declaration. virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg AssertExpr, - ExprArg AssertMessageExpr, - SourceLocation RParenLoc) { + ExprArg AssertMessageExpr) { return 0; } diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index f534f42ccb..ec91d71b08 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -252,13 +252,12 @@ Parser::DeclTy *Parser::ParseStaticAssertDeclaration() { if (AssertMessage.isInvalid()) return 0; - SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); + MatchRHSPunctuation(tok::r_paren, LParenLoc); ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert); return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr), - move(AssertMessage), - RParenLoc); + move(AssertMessage)); } /// ParseClassName - Parse a C++ class-name, which names a class. Note diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index a357ae7621..29d0796dcb 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1562,8 +1562,7 @@ public: virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg AssertExpr, - ExprArg AssertMessageExpr, - SourceLocation RParenLoc); + ExprArg AssertMessageExpr); bool CheckConstructorDeclarator(Declarator &D, QualType &R, FunctionDecl::StorageClass& SC); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 177eee2a53..fa84c7d2de 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2238,8 +2238,7 @@ Sema::DeclTy *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, ExprArg assertexpr, - ExprArg assertmessageexpr, - SourceLocation RParenLoc) { + ExprArg assertmessageexpr) { Expr *AssertExpr = (Expr *)assertexpr.get(); StringLiteral *AssertMessage = cast<StringLiteral>((Expr *)assertmessageexpr.get()); @@ -2255,7 +2254,8 @@ Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, if (Value == 0) { std::string str(AssertMessage->getStrData(), AssertMessage->getByteLength()); - Diag(AssertLoc, diag::err_static_assert_failed) << str; + Diag(AssertLoc, diag::err_static_assert_failed) + << str << AssertExpr->getSourceRange(); } } diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 7b2d24b5bf..b7f0bbc923 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1071,6 +1071,25 @@ Sema::InstantiateClassTemplateSpecialization( if (New->isInvalidDecl()) Invalid = true; } + } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(*Member)) { + Expr *AssertExpr = SA->getAssertExpr(); + + OwningExprResult InstantiatedAssertExpr + = InstantiateExpr(AssertExpr, + ClassTemplateSpec->getTemplateArgs(), + ClassTemplateSpec->getNumTemplateArgs()); + if (!InstantiatedAssertExpr.isInvalid()) { + OwningExprResult Message = Clone(SA->getMessage()); + + Decl *New = + (Decl *)ActOnStaticAssertDeclaration(SA->getLocation(), + move(InstantiatedAssertExpr), + move(Message)); + if (New->isInvalidDecl()) + Invalid = true; + + } else + Invalid = true; } } diff --git a/test/SemaCXX/static-assert.cpp b/test/SemaCXX/static-assert.cpp index 94ffff86cd..7e1ee467ad 100644 --- a/test/SemaCXX/static-assert.cpp +++ b/test/SemaCXX/static-assert.cpp @@ -15,10 +15,16 @@ class C { }; template<int N> struct T { - static_assert(N == 2, "N is not 2!"); + static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed "N is not 2!"}} }; +T<1> t1; // expected-note {{in instantiation of template class 'struct T<1>' requested here}} +T<2> t2; + template<typename T> struct S { - static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); + static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed "Type not big enough!"}} }; +S<char> s1; // expected-note {{in instantiation of template class 'struct S<char>' requested here}} +S<int> s2; + |