xref: /llvm-project/clang/test/CXX/temp/temp.spec/cxx1y-variable-template-no-body.cpp (revision c660c8f5d2c76fe0cb18cd027057a58e2cb5de7b)
139a1e507SLarisse Voufo // RUN: %clang_cc1 --std=c++1y -fsyntax-only -verify %s
239a1e507SLarisse Voufo // RUN: cp %s %t
339a1e507SLarisse Voufo // RUN: not %clang_cc1 --std=c++1y -x c++ -fixit %t -DFIXING
439a1e507SLarisse Voufo // RUN: %clang_cc1 --std=c++1y -x c++ %t -DFIXING
539a1e507SLarisse Voufo 
639a1e507SLarisse Voufo template<typename T>
739a1e507SLarisse Voufo T pi = T(3.1415926535897932385); // expected-note {{template is declared here}}
839a1e507SLarisse Voufo 
939a1e507SLarisse Voufo template int pi<int>;
1039a1e507SLarisse Voufo 
1139a1e507SLarisse Voufo #ifndef FIXING
120c062b40SRichard Smith template float pi<>; // expected-error {{too few template arguments for variable template 'pi'}}
1339a1e507SLarisse Voufo template double pi_var0; // expected-error {{explicit instantiation of 'pi_var0' does not refer to a function template, variable template, member function, member class, or static data member}}
1439a1e507SLarisse Voufo #endif
1539a1e507SLarisse Voufo 
1639a1e507SLarisse Voufo // Should recover as if definition
1739a1e507SLarisse Voufo template double pi_var = 5; // expected-error {{variable cannot be defined in an explicit instantiation; if this declaration is meant to be a variable definition, remove the 'template' keyword}}
1839a1e507SLarisse Voufo #ifndef FIXING
1939a1e507SLarisse Voufo template<typename T>
2039a1e507SLarisse Voufo T pi0 = T(3.1415926535897932385); // expected-note {{previous definition is here}}
2139a1e507SLarisse Voufo 
2239a1e507SLarisse Voufo template int pi0 = 10; // expected-error {{variable cannot be defined in an explicit instantiation; if this declaration is meant to be a variable definition, remove the 'template' keyword}} \
23d8dd97c0SLarisse Voufo                           expected-error{{redefinition of 'pi0' as different kind of symbol}}
2439a1e507SLarisse Voufo #endif
2539a1e507SLarisse Voufo 
2639a1e507SLarisse Voufo template<typename T>
27beef3453SRichard Smith T pi1 = T(3.1415926535897932385); // expected-note 0-2 {{here}}
2839a1e507SLarisse Voufo 
2939a1e507SLarisse Voufo // Should recover as if specialization
3039a1e507SLarisse Voufo template float pi1<float> = 1.0;  // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}
3139a1e507SLarisse Voufo namespace expected_global {
32*c660c8f5SRichard Smith #ifndef FIXING
33*c660c8f5SRichard Smith   template int pi1<int> = 10;  // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} expected-error {{must occur at global scope}}
3439a1e507SLarisse Voufo #endif
35*c660c8f5SRichard Smith }
36