Clang Project

clang_source_code/test/CXX/temp/temp.decls/temp.class/temp.static/p1-inst.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5// Test instantiation of static data members declared out-of-line.
6
7template<typename T>
8struct X {
9  static T value;
10};
11
12template<typename T> 
13  T X<T>::value = 17; // expected-error{{no viable conversion}}
14
15struct InitOkay {
16  InitOkay(int) { }
17};
18
19struct CannotInit { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
20#if __cplusplus >= 201103L // C++11 or later
21// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}
22#endif
23
24int &returnInt() { return X<int>::value; }
25float &returnFloat() { return X<float>::value; }
26
27InitOkay &returnInitOkay() { return X<InitOkay>::value; }
28
29unsigned long sizeOkay() { return sizeof(X<CannotInit>::value); }
30  
31CannotInit &returnError() {
32  return X<CannotInit>::value; // expected-note{{instantiation}}
33}
34