summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaTemplate/fibonacci.cpp25
-rw-r--r--clang/test/SemaTemplate/instantiate-static-var.cpp18
2 files changed, 43 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/fibonacci.cpp b/clang/test/SemaTemplate/fibonacci.cpp
index aa3b4b1b671..e8a1ec772e8 100644
--- a/clang/test/SemaTemplate/fibonacci.cpp
+++ b/clang/test/SemaTemplate/fibonacci.cpp
@@ -25,3 +25,28 @@ template<> struct Fibonacci<1> {
int array5[Fibonacci<5>::value == 5? 1 : -1];
int array10[Fibonacci<10>::value == 55? 1 : -1];
+
+template<unsigned I>
+struct FibonacciEval2;
+
+template<unsigned I>
+struct Fibonacci2 {
+ static const unsigned value
+ = FibonacciEval2<I-1>::value + FibonacciEval2<I-2>::value;
+};
+
+template<unsigned I>
+struct FibonacciEval2 {
+ static const unsigned value = Fibonacci2<I>::value;
+};
+
+template<> struct Fibonacci2<0> {
+ static const unsigned value = 0;
+};
+
+template<> struct Fibonacci2<1> {
+ static const unsigned value = 1;
+};
+
+int array5_2[Fibonacci2<5>::value == 5? 1 : -1];
+int array10_2[Fibonacci2<10>::value == 55? 1 : -1];
diff --git a/clang/test/SemaTemplate/instantiate-static-var.cpp b/clang/test/SemaTemplate/instantiate-static-var.cpp
new file mode 100644
index 00000000000..99e6b9cc06c
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-static-var.cpp
@@ -0,0 +1,18 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T, T Divisor>
+class X {
+public:
+ static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}}
+};
+
+int array1[X<int, 2>::value == 5? 1 : -1];
+X<int, 0> xi0; // expected-note{{in instantiation of template class 'class X<int, 0>' requested here}}
+
+
+template<typename T>
+class Y {
+ static const T value = 0; // expected-error{{'value' can only be initialized if it is a static const integral data member}}
+};
+
+Y<float> fy; // expected-note{{in instantiation of template class 'class Y<float>' requested here}}
OpenPOWER on IntegriCloud