]> granicus.if.org Git - clang/commitdiff
[Sema] Don't crash if array bound calculation overflowed constexpr array
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 18 Apr 2015 04:55:51 +0000 (04:55 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 18 Apr 2015 04:55:51 +0000 (04:55 +0000)
We didn't correctly expect a QualifiedTypeLoc when faced with fixing a
variable array type into a constant array type.

Differential Revision: http://reviews.llvm.org/D8958

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CXX/basic/basic.types/p10.cpp

index 1bad38f53b816034ea1347ceb791bec46a38d768..f6cb2829cf5a0292da4ecdbd72282145c9214a4c 100644 (file)
@@ -4891,6 +4891,8 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
 
 static void
 FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL) {
+  SrcTL = SrcTL.getUnqualifiedLoc();
+  DstTL = DstTL.getUnqualifiedLoc();
   if (PointerTypeLoc SrcPTL = SrcTL.getAs<PointerTypeLoc>()) {
     PointerTypeLoc DstPTL = DstTL.castAs<PointerTypeLoc>();
     FixInvalidVariablyModifiedTypeLoc(SrcPTL.getPointeeLoc(),
index 7b1af00b5d5c7dacb047dc7f5b898fa7c15a22ee..19258f80f517d041174ae255dac2e6ab5895c56b 100644 (file)
@@ -139,3 +139,5 @@ constexpr int f(ArrBad) { return 0; } // expected-error {{1st parameter type 'Ar
 constexpr int arb(int n) {
   int a[n]; // expected-error {{variable of non-literal type 'int [n]' cannot be defined in a constexpr function}}
 }
+constexpr long Overflow[ // expected-error {{constexpr variable cannot have non-literal type 'long const[(1 << 30) << 2]'}}
+    (1 << 30) << 2]{};   // expected-warning {{requires 34 bits to represent}}