Debian Codegraph @

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

raw
1 // { dg-do compile }
2
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 24 Jun 2004 <[email protected]>
5
6 // Origin Rani Sharoni via [email protected]
7 // Bug 16174, SFINAE failure.
8
9 template <class T> struct K
10 {
11 K();
12
13 K(K<T> & rhs);
14 K(K<T> const& rhs);
15 template <class U> K(K<U> const& rhs);
16
17 private:
18 template <class U> struct A;
19 template <class U> struct A< K<U> const>
20 { typedef typename K<U>::compile_time_error type; };
21
22 // This is used to reject calls to the copy constructor
23 // with objects which are top-level const. If they are
24 // const, the specialization of A is instantiated and
25 // causes a compile time error. Otherwise, the general
26 // template is picked up, it misses definition, so this
27 // ctor declaration is rejected by SFINAE and everybody
28 // is happy.
29 // GCC 3.4.1pre and 3.5.0 always matches A's specialization
30 // when instantiating from foo(), and this causes the error.
31 template <class U>
32 K(U& rhs, typename A<U>::type = 0);
33 };
34
35
36 K<int> foo(void)
37 {
38 return K<int>();
39 }