brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 25cb916 Raw
68 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s2// RUN: %clang_cc1 -fsyntax-only -std=c++1y -verify %s -DCXX1Y3 4#ifndef CXX1Y5 6template<typename T, typename U, U> using alias_ref = T;7template<typename T, typename U, U> void func_ref() {}8template<typename T, typename U, U> struct class_ref {};9 10template<int N>11struct U {12  static int a;13};14 15template<int N> struct S; // expected-note 6{{here}}16 17template<int N>18int U<N>::a = S<N>::kError; // expected-error 6{{undefined}}19 20template<typename T>21void f() {22  (void)alias_ref<int, int&, U<0>::a>(); // expected-note {{here}}23  (void)func_ref<int, int&, U<1>::a>(); // expected-note {{here}}24  (void)class_ref<int, int&, U<2>::a>(); // expected-note {{here}}25};26 27template<typename T>28void not_instantiated() {29  // These cases (arguably) do not require instantiation of U<i>::a.30  (void)alias_ref<int, int&, U<3>::a>();31  (void)func_ref<int, int&, U<4>::a>();32  (void)class_ref<int, int&, U<5>::a>();33};34 35template<int N>36void fi() {37  (void)alias_ref<int, int&, U<N>::a>(); // expected-note {{here}}38  (void)func_ref<int, int&, U<N+1>::a>(); // expected-note {{here}}39  (void)class_ref<int, int&, U<N+2>::a>(); // expected-note {{here}}40};41 42int main() {43  f<int>();   // expected-note 3{{here}}44  fi<10>();   // expected-note 3{{here}}45}46 47namespace N {48  template<typename T> struct S { static int n; }; // expected-note {{declared here}}49  template<typename T> int S<T>::n = 5;50  void g(int*);51  template<typename T> int f() {52    int k[S<T>::n]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \53                       expected-note {{read of non-const variable 'n' is not allowed in a constant expression}}54    g(k);55    return k[3];56  }57  int j = f<int>(); // expected-note {{in instantiation of function template specialization 'N::f<int>' requested here}}58}59 60#else61 62namespace { template<typename> extern int n; }63template<typename T> int g() { return n<int>; }64namespace { extern template int n<int>; } // expected-error {{explicit instantiation declaration of 'n<int>' with internal linkage}}65 66#endif67 68