Author: compnerd Date: Fri Jun 3 22:16:21 2016 New Revision: 271762 URL: http://llvm.org/viewvc/llvm-project?rev=271762&view=rev Log: 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. Added: cfe/trunk/test/SemaCXX/eval-sizeof-dependent-type.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=271762&r1=271761&r2=271762&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jun 3 22:16:21 2016 @@ -2024,6 +2024,11 @@ static bool HandleSizeof(EvalInfo &Info, 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. Added: cfe/trunk/test/SemaCXX/eval-sizeof-dependent-type.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/eval-sizeof-dependent-type.cpp?rev=271762&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/eval-sizeof-dependent-type.cpp (added) +++ cfe/trunk/test/SemaCXX/eval-sizeof-dependent-type.cpp Fri Jun 3 22:16:21 2016 @@ -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))}; +}; + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits