summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-11-08 01:31:09 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-11-08 01:31:09 +0000
commitec8dcd2716e8cfd651b096eaa843f721ca8001e0 (patch)
tree8e64c736423f869f8ae5e0dbddc6b57ac17d6944 /clang/lib/AST/ExprConstant.cpp
parentf2a9bd4b1ec21ed04fdac9b7120582eb6f800486 (diff)
downloadbcm5719-llvm-ec8dcd2716e8cfd651b096eaa843f721ca8001e0.tar.gz
bcm5719-llvm-ec8dcd2716e8cfd651b096eaa843f721ca8001e0.zip
Fix a cluster of related issues involving value-dependence and constant
expression evaluation: - When folding a non-value-dependent expression, we may try to use the initializer of a value-dependent variable. If that happens, give up. - In C++98, actually check that a const, non-volatile DeclRefExpr inside an ICE is of integral or enumeration type (a reference isn't OK!) - In C++11, DeclRefExprs for objects of const literal type initialized with value-dependent expressions are themselves value-dependent. - So are references initialized with value-dependent expressions (though this case is missing from the C++11 standard, along with many others). llvm-svn: 144056
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 746b094619c..d6e263b4476 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -552,7 +552,7 @@ static bool EvaluateVarDeclInit(EvalInfo &Info, const VarDecl *VD,
return false;
const Expr *Init = VD->getAnyInitializer();
- if (!Init)
+ if (!Init || Init->isValueDependent())
return false;
if (APValue *V = VD->getEvaluatedValue()) {
@@ -3640,6 +3640,9 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
// A variable of non-volatile const-qualified integral or enumeration
// type initialized by an ICE can be used in ICEs.
if (const VarDecl *Dcl = dyn_cast<VarDecl>(D)) {
+ if (!Dcl->getType()->isIntegralOrEnumerationType())
+ return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
+
// Look for a declaration of this variable that has an initializer.
const VarDecl *ID = 0;
const Expr *Init = Dcl->getAnyInitializer(ID);
OpenPOWER on IntegriCloud