brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 5b0c4be Raw
91 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4// RUN: cp %s %t5// RUN: not %clang_cc1 -x c++ -fixit %t -DFIXING6// RUN: %clang_cc1 -x c++ %t -DFIXING7 8template<typename T> void f(T) { }9#if __cplusplus >= 201103L10  // expected-note@-2 {{explicit instantiation refers here}}11#endif12 13template<typename T> void g(T) { }14#if __cplusplus >= 201103L15  // expected-note@-2 {{explicit instantiation refers here}}16#endif17 18template<typename T> struct x { };19#if __cplusplus >= 201103L20  // expected-note@-2 {{explicit instantiation refers here}}21#endif22 23template<typename T> struct y { };  // expected-note {{declared here}}24 25namespace good { // Only good in C++98/0326#ifndef FIXING27  template void f<int>(int);28#if __cplusplus >= 201103L29  // expected-error@-2 {{explicit instantiation of 'f' must occur at global scope}}30#endif31 32  template void g(int);33#if __cplusplus >= 201103L34  // expected-error@-2 {{explicit instantiation of 'g' must occur at global scope}}35#endif36 37  template struct x<int>;38#if __cplusplus >= 201103L39  // expected-error@-2 {{explicit instantiation of 'x' must occur at global scope}}40#endif41#endif42}43 44namespace unsupported {45#ifndef FIXING46 template struct y;     // expected-error {{template 'y' cannot be referenced with the 'struct' specifier}}47#endif48}49 50template<typename T> void f0(T) { }51template<typename T> void g0(T) { }52template<typename T> struct x0 { }; // expected-note {{explicitly specialized declaration is here}}53template<typename T> struct y0 { };54 55// Should recover as if definition56namespace noargs_body {57#ifndef FIXING58  template void g0(int) { } // expected-error {{function cannot be defined in an explicit instantiation; if this declaration is meant to be a function definition, remove the 'template' keyword}}59#endif60  template struct y0 { };     // expected-error {{class cannot be defined in an explicit instantiation; if this declaration is meant to be a class definition, remove the 'template' keyword}}61}62 63// Explicit specializations expected in global scope64namespace exp_spec {65#ifndef FIXING66  template<> void f0<int>(int) { }  // expected-error {{no function template matches function template specialization 'f0'}}67  template<> struct x0<int> { };    // expected-error {{class template specialization of 'x0' must occur at global scope}}68#endif69}70 71template<typename T> void f1(T) { }72template<typename T> struct x1 { };  // expected-note {{explicitly specialized declaration is here}}73 74// Should recover as if specializations, 75// thus also complain about not being in global scope.76namespace args_bad {77#ifndef FIXING78  template void f1<int>(int) { }    // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \79                                       expected-error {{no function template matches function template specialization 'f1'}}80  template struct x1<int> { };      // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \81                                       expected-error {{class template specialization of 'x1' must occur at global scope}}82#endif83}84 85template<typename T> void f2(T) { }86template<typename T> struct x2 { };87 88// Should recover as if specializations89template void f2<int>(int) { }    // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}90template struct x2<int> { };      // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}91