1 Pull in r200899 from upstream clang trunk (by Serge Pavlov):
3 Allow transformation of VariableArray to ConstantArray.
7 struct A { static const int sz; };
8 template<class T> void f() { T arr[A::sz]; }
10 the array 'arr' is represented as a variable size array in the template.
11 If 'A::sz' gets value below in the translation unit, the array in
12 instantiation can turn into constant size array.
14 This change fixes PR18633.
16 Differential Revision: http://llvm-reviews.chandlerc.com/D2688
18 Introduced here: http://svnweb.freebsd.org/changeset/base/261680
20 Index: tools/clang/test/SemaCXX/c99-variable-length-array.cpp
21 ===================================================================
22 --- tools/clang/test/SemaCXX/c99-variable-length-array.cpp
23 +++ tools/clang/test/SemaCXX/c99-variable-length-array.cpp
24 @@ -140,3 +140,24 @@ namespace PR11744 {
26 int test = f<int>(0); // expected-note {{instantiation of}}
31 + static const int sz;
32 + static const int sz2;
34 + const int A1::sz2 = 11;
35 + template<typename T>
37 + int arr[A1::sz]; // expected-warning{{variable length arrays are a C99 feature}}
39 + template<typename T>
43 + const int A1::sz = 12;
49 Index: tools/clang/lib/Sema/TreeTransform.h
50 ===================================================================
51 --- tools/clang/lib/Sema/TreeTransform.h
52 +++ tools/clang/lib/Sema/TreeTransform.h
53 @@ -3966,7 +3966,9 @@ TreeTransform<Derived>::TransformVariableArrayType
57 - VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
58 + // We might have constant size array now, but fortunately it has the same
60 + ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
61 NewTL.setLBracketLoc(TL.getLBracketLoc());
62 NewTL.setRBracketLoc(TL.getRBracketLoc());
63 NewTL.setSizeExpr(Size);