Sema: do not attempt to sizeof a dependent type

We would attempt to evaluate the sizeof a dependent type to check for an
integral overflow.  However, because the dependent type is not yet resolved, we
cannot determine if the expression would overflow.  Report a failure to perform
a symbolic evaluation of a constant involving the dependent type.

llvm-svn: 271762
This commit is contained in:
Saleem Abdulrasool 2016-06-04 03:16:21 +00:00
parent 1c1101bb33
commit ada78feb08
2 changed files with 13 additions and 0 deletions

View File

@ -2024,6 +2024,11 @@ static bool HandleSizeof(EvalInfo &Info, SourceLocation Loc,
return true; return true;
} }
if (Type->isDependentType()) {
Info.Diag(Loc);
return false;
}
if (!Type->isConstantSizeType()) { if (!Type->isConstantSizeType()) {
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
// FIXME: Better diagnostic. // FIXME: Better diagnostic.

View File

@ -0,0 +1,8 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c++11 -x c++ %s
typedef __SIZE_TYPE__ size_t;
template <typename _Tp, size_t _Nm> struct array { _Tp _M_elems[_Nm]; };
template <typename T> struct s {
array<int, 1> v{static_cast<int>(sizeof (T) / sizeof(T))};
};