From ada78feb08e1924c4f18fa91b6f30627733a4aba Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 4 Jun 2016 03:16:21 +0000 Subject: [PATCH] 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 --- clang/lib/AST/ExprConstant.cpp | 5 +++++ clang/test/SemaCXX/eval-sizeof-dependent-type.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 clang/test/SemaCXX/eval-sizeof-dependent-type.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 10192be7bdf1..8c24b0333e1f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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/clang/test/SemaCXX/eval-sizeof-dependent-type.cpp b/clang/test/SemaCXX/eval-sizeof-dependent-type.cpp new file mode 100644 index 000000000000..1a5564a477d8 --- /dev/null +++ b/clang/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))}; +}; +