]> granicus.if.org Git - clang/commitdiff
Sema: do not attempt to sizeof a dependent type
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 4 Jun 2016 03:16:21 +0000 (03:16 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 4 Jun 2016 03:16:21 +0000 (03:16 +0000)
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

lib/AST/ExprConstant.cpp
test/SemaCXX/eval-sizeof-dependent-type.cpp [new file with mode: 0644]

index 10192be7bdf1e516a7726f285ab44f4cb2a1f886..8c24b0333e1f4762bb219a7de599232c9b4e179b 100644 (file)
@@ -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 (file)
index 0000000..1a5564a
--- /dev/null
@@ -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))};
+};
+