xref: /llvm-project/clang/test/Misc/diag-template-diffing-cxx98.cpp (revision c4a1e0efe6b0767dfb5861a7e8814d7db0c0de8a)
1 // RUN: not %clang_cc1 -fsyntax-only %s -std=c++98 2>&1 | FileCheck %s
2 
3 namespace PR14342 {
4   template<typename T, char a> struct X {};
5   X<int, 1> x = X<long, 257>();
6   // CHECK: error: no viable conversion from 'X<long, [...]>' to 'X<int, [...]>'
7 }
8 
9 namespace PR15513 {
10   template <int x, int y = x+1>
11   class A {};
12 
13   void foo(A<0> &M) {
14     // CHECK: no viable conversion from 'A<[...], (default) x + 1 aka 1>' to 'A<[...], 0>'
15     A<0, 0> N = M;
16    // CHECK: no viable conversion from 'A<0, [...]>' to 'A<1, [...]>'
17     A<1, 1> O = M;
18   }
19 }
20 
21 namespace default_args {
22   template <int x, int y = 1+1, int z = 2>
23   class A {};
24 
25   void foo(A<0> &M) {
26     // CHECK: no viable conversion from 'A<[...], (default) 1 + 1 aka 2, (default) 2>' to 'A<[...], 0, 0>'
27     A<0, 0, 0> N = M;
28 
29     // CHECK: no viable conversion from 'A<[2 * ...], (default) 2>' to 'A<[2 * ...], 0>'
30     A<0, 2, 0> N2 = M;
31   }
32 
33 }
34 
35 namespace qualifiers {
36   template <class T>
37   void foo(void (func(T*)), T*) {}
38 
39   template <class T>
40   class vector{};
41 
42   void bar(const vector<int>*) {}
43 
44   void test(volatile vector<int>* V) {
45     foo(bar, V);
46   }
47 
48   // CHECK: candidate template ignored: deduced conflicting types for parameter 'T' ('const vector<...>' vs. 'volatile vector<...>')
49 }
50 
51 namespace integers {
52   template <int x>
53   class wrapper{};
54 
55   template <int x>
56   class foo {
57    public:
58     wrapper<x> make();
59   };
60 
61   wrapper<1> w1 = foo<2>().make();
62   // CHECK: no viable conversion from 'wrapper<2>' to 'wrapper<1>'
63 
64   wrapper<1> w2 = foo<-3>().make();
65   // CHECK: no viable conversion from 'wrapper<-3>' to 'wrapper<1>'
66 
67   template <int x>
68   wrapper<x> make();
69 
70   wrapper<1> w3 = make<4>();
71   // CHECK: no viable conversion from 'wrapper<4>' to 'wrapper<1>'
72 
73   template <int x>
74   wrapper<-x> makeNegative();
75 
76   wrapper<1> w4 = makeNegative<5>();
77   // CHECK: no viable conversion from 'wrapper<-5>' to 'wrapper<1>'
78 
79   wrapper<1> w5 = makeNegative<-6>();
80   // CHECK: no viable conversion from 'wrapper<6>' to 'wrapper<1>'
81 }
82