diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-05 02:30:54 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-05 02:30:54 +0000 |
commit | 2de5a939e2f1fe6773865af021608ccc368b2418 (patch) | |
tree | 219b6a5e88d1e609b92ba989fb42b8c2caf6eb43 /clang/lib | |
parent | 9c81833c8dbe3d903d6df71a62c705c06a2f0e9a (diff) | |
download | bcm5719-llvm-2de5a939e2f1fe6773865af021608ccc368b2418.tar.gz bcm5719-llvm-2de5a939e2f1fe6773865af021608ccc368b2418.zip |
constexpr: Implement DR1358: An instantiation of a constexpr function which
can't produce a constant expression is not ill-formed (so long as some
instantiation of that function can produce a constant expression).
llvm-svn: 149802
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6b92b0ad67c..172e931153d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7302,7 +7302,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, } if (FD && FD->isConstexpr() && !FD->isInvalidDecl() && - !CheckConstexprFunctionBody(FD, Body)) + !CheckConstexprFunctionBody(FD, Body, IsInstantiation)) FD->setInvalidDecl(); assert(ExprCleanupObjects.empty() && "Leftover temporaries in function"); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index a52d44c4f2e..10883af4b41 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -837,7 +837,8 @@ static void CheckConstexprCtorInitializer(Sema &SemaRef, /// the permitted types of statement. C++11 [dcl.constexpr]p3,p4. /// /// \return true if the body is OK, false if we have diagnosed a problem. -bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body) { +bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body, + bool IsInstantiation) { if (isa<CXXTryStmt>(Body)) { // C++11 [dcl.constexpr]p3: // The definition of a constexpr function shall satisfy the following @@ -989,7 +990,7 @@ bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body) { // can't produce constant expressions. llvm::SmallVector<PartialDiagnosticAt, 8> Diags; if (!Context.getSourceManager().isInSystemHeader(Dcl->getLocation()) && - !Expr::isPotentialConstantExpr(Dcl, Diags)) { + !IsInstantiation && !Expr::isPotentialConstantExpr(Dcl, Diags)) { Diag(Dcl->getLocation(), diag::err_constexpr_function_never_constant_expr) << isa<CXXConstructorDecl>(Dcl); for (size_t I = 0, N = Diags.size(); I != N; ++I) |