Debian Codegraph @

gcc/testsuite/g++.dg/template/dr408.C

raw
1 // DR 408
2 // { dg-do link }
3
4 // Test that a size given in the out-of-class definition isn't used until
5 // instantiation time.
6 template<typename T>
7 struct X
8 {
9 static char s[];
10 int c;
11 };
12
13 template<typename T>
14 char X<T>::s[sizeof(X<T>)];
15
16 #define sassert(EXP) int ar[(EXP)?1:-1]
17 sassert(sizeof (X<char>::s) == sizeof (int));
18
19 // Test that a specialization can have a different size.
20
21 template <int> void g();
22 template <> void g<2>() { }
23
24 template <typename T>
25 struct S {
26 static int i[];
27 void f();
28 };
29
30 template <typename T>
31 int S<T>::i[] = { 1 };
32
33 template <typename T>
34 void S<T>::f() {
35 g<sizeof (i) / sizeof (int)>();
36 }
37
38 template <>
39 int S<int>::i[] = { 1, 2 };
40
41 int main()
42 {
43 S<int> s;
44 s.f();
45 }