Skip to content

Commit ada78fe

Browse files
committed
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
1 parent 1c1101b commit ada78fe

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,11 @@ static bool HandleSizeof(EvalInfo &Info, SourceLocation Loc,
20242024
return true;
20252025
}
20262026

2027+
if (Type->isDependentType()) {
2028+
Info.Diag(Loc);
2029+
return false;
2030+
}
2031+
20272032
if (!Type->isConstantSizeType()) {
20282033
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
20292034
// FIXME: Better diagnostic.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c++11 -x c++ %s
2+
3+
typedef __SIZE_TYPE__ size_t;
4+
template <typename _Tp, size_t _Nm> struct array { _Tp _M_elems[_Nm]; };
5+
template <typename T> struct s {
6+
array<int, 1> v{static_cast<int>(sizeof (T) / sizeof(T))};
7+
};
8+

0 commit comments

Comments
 (0)