<rdar://problem/13584715> Converted constant expressions are expected to have integral values.

We were assuming that any expression used as a converted constant
expression would either not have a folded constant value or would be
an integer, which is not the case for some ill-formed constant
expressions. Because converted constant expressions are only used
where integral values are expected, we can simply treat this as an
error path. If that ever changes, we'll need to widen the interface of
Sema::CheckConvertedConstantExpression() anyway.

llvm-svn: 179068
This commit is contained in:
Douglas Gregor 2013-04-08 23:24:07 +00:00
parent cc9406c055
commit ebe2db7ed6
2 changed files with 17 additions and 1 deletions

View File

@ -5024,7 +5024,7 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T,
Expr::EvalResult Eval;
Eval.Diag = &Notes;
if (!Result.get()->EvaluateAsRValue(Eval, Context)) {
if (!Result.get()->EvaluateAsRValue(Eval, Context) || !Eval.Val.isInt()) {
// The expression can't be folded, so we can't keep it at this position in
// the AST.
Result = ExprError();

View File

@ -137,3 +137,19 @@ namespace DR1364 {
return kGlobal; // expected-note {{read of non-const}}
}
}
namespace rdar13584715 {
typedef __PTRDIFF_TYPE__ ptrdiff_t;
template<typename T> struct X {
static T value() {};
};
void foo(ptrdiff_t id) {
switch (id) {
case reinterpret_cast<ptrdiff_t>(&X<long>::value): // expected-error{{case value is not a constant expression}} \
// expected-note{{reinterpret_cast is not allowed in a constant expression}}
break;
}
}
}