From: Saleem Abdulrasool Date: Sat, 4 Jun 2016 03:16:21 +0000 (+0000) Subject: Sema: do not attempt to sizeof a dependent type X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf100fba2a2de4c3b9f97528fc8e003058364964;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271762 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 10192be7bd..8c24b0333e 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2024,6 +2024,11 @@ static bool HandleSizeof(EvalInfo &Info, SourceLocation Loc, return true; } + if (Type->isDependentType()) { + Info.Diag(Loc); + return false; + } + if (!Type->isConstantSizeType()) { // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. // FIXME: Better diagnostic. diff --git a/test/SemaCXX/eval-sizeof-dependent-type.cpp b/test/SemaCXX/eval-sizeof-dependent-type.cpp new file mode 100644 index 0000000000..1a5564a477 --- /dev/null +++ b/test/SemaCXX/eval-sizeof-dependent-type.cpp @@ -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 struct array { _Tp _M_elems[_Nm]; }; +template struct s { + array v{static_cast(sizeof (T) / sizeof(T))}; +}; +