• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fcolor-diagnostics %s 2>&1 | FileCheck %s
2 // RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fcolor-diagnostics -fdiagnostics-show-template-tree %s 2>&1 | FileCheck %s -check-prefix=TREE
3 // REQUIRES: ansi-escape-sequences
4 template<typename> struct foo {};
5 void func(foo<int>);
main()6 int main() {
7   func(foo<double>());
8 }
9 // CHECK: {{.*}}candidate function not viable: no known conversion from 'foo<[[CYAN:.\[0;1;36m]]double[[RESET:.\[0m]]>' to 'foo<[[CYAN]]int[[RESET]]>' for 1st argument[[RESET]]
10 // TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
11 // TREE:  foo<
12 // TREE:    {{\[}}[[CYAN:.\[0;1;36m]]double[[RESET:.\[0m]] != [[CYAN]]int[[RESET]]]>[[RESET]]
13 
14 foo<int> A;
15 foo<double> &B = A;
16 // CHECK: {{.*}}non-const lvalue reference to type 'foo<[[CYAN]]double[[RESET]][[BOLD:.\[1m]]>' cannot bind to a value of unrelated type 'foo<[[CYAN]]int[[RESET]][[BOLD]]>'[[RESET]]
17 // TREE: non-const lvalue reference cannot bind to a value of unrelated type
18 // TREE:   foo<
19 // TREE:     {{\[}}[[CYAN]]double[[RESET]][[BOLD:.\[1m]] != [[CYAN]]int[[RESET]][[BOLD]]]>[[RESET]]
20 
21 template<typename> class vector {};
22 
set15(vector<const vector<int>>)23 void set15(vector<const vector<int> >) {}
test15()24 void test15() {
25   set15(vector<const vector<const int> >());
26 }
27 // CHECK: {{.*}}candidate function not viable: no known conversion from 'vector<const vector<[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}int>>' to 'vector<const vector<int>>' for 1st argument
28 // TREE: {{.*}}candidate function not viable: no known conversion from argument type to parameter type for 1st argument
29 // TREE:   vector<
30 // TREE:     const vector<
31 // TREE:       {{\[}}[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}!= [[CYAN]](no qualifiers)[[RESET]]] int>>
32 
set16(vector<vector<int>>)33 void set16(vector<vector<int> >) {}
test16()34 void test16() {
35   set16(vector<const vector<int> >());
36 }
37 // CHECK: {{.*}}candidate function not viable: no known conversion from 'vector<[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}vector<...>>' to 'vector<vector<...>>' for 1st argument
38 // TREE: {{.*}}candidate function not viable: no known conversion from argument type to parameter type for 1st argument
39 // TREE:   vector<
40 // TREE:     {{\[}}[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}!= [[CYAN]](no qualifiers){{ ?}}[[RESET]]]{{ ?}}vector<...>>
41 
set17(vector<const vector<int>>)42 void set17(vector<const vector<int> >) {}
test17()43 void test17() {
44   set17(vector<vector<int> >());
45 }
46 // CHECK: candidate function not viable: no known conversion from 'vector<vector<...>>' to 'vector<[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}vector<...>>' for 1st argument
47 // TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
48 // TREE:   vector<
49 // TREE:     {{\[}}[[CYAN]](no qualifiers){{ ?}}[[RESET]]{{ ?}}!= [[CYAN]]const[[RESET]]] vector<...>>
50 
set18(vector<volatile vector<int>>)51 void set18(vector<volatile vector<int> >) {}
test18()52 void test18() {
53   set18(vector<const vector<int> >());
54 }
55 // CHECK: candidate function not viable: no known conversion from 'vector<[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}vector<...>>' to 'vector<[[CYAN]]volatile{{ ?}}[[RESET]]{{ ?}}vector<...>>' for 1st argument
56 // TREE: no matching function for call to 'set18'
57 // TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
58 // TREE:   vector<
59 // TREE:     {{\[}}[[CYAN]]const{{ ?}}[[RESET]]{{ ?}}!= [[CYAN]]volatile[[RESET]]] vector<...>>
60 
set19(vector<const volatile vector<int>>)61 void set19(vector<const volatile vector<int> >) {}
test19()62 void test19() {
63   set19(vector<const vector<int> >());
64 }
65 // CHECK: candidate function not viable: no known conversion from 'vector<const vector<...>>' to 'vector<const [[CYAN]]volatile{{ ?}}[[RESET]]{{ ?}}vector<...>>' for 1st argument
66 // TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
67 // TREE:   vector<
68 // TREE:     [const != const [[CYAN]]volatile[[RESET]]] vector<...>>
69 
70 namespace default_args {
71   template <int x, int y = 1+1, int z = 2>
72   class A {};
73 
foo(A<0> & M)74   void foo(A<0> &M) {
75     // CHECK: no viable conversion from 'A<[...], (default) [[CYAN]]1 + 1[[RESET]][[BOLD]] aka [[CYAN]]2[[RESET]][[BOLD]], (default) [[CYAN]]2[[RESET]][[BOLD]]>' to 'A<[...], [[CYAN]]0[[RESET]][[BOLD]], [[CYAN]]0[[RESET]][[BOLD]]>'
76     A<0, 0, 0> N = M;
77 
78     // CHECK: no viable conversion from 'A<[2 * ...], (default) [[CYAN]]2[[RESET]][[BOLD]]>' to 'A<[2 * ...], [[CYAN]]0[[RESET]][[BOLD]]>'
79     A<0, 2, 0> N2 = M;
80   }
81 }
82 
83 namespace MixedDeclarationIntegerArgument {
84   template<typename T, T n = 5> class A{};
85   int x;
86   int y[5];
87   A<int> a1 = A<int&, x>();
88   // CHECK: no viable conversion from 'A<[[CYAN]]int &[[RESET]][[BOLD]], [[CYAN]]x[[RESET]][[BOLD]]>' to 'A<[[CYAN]]int[[RESET]][[BOLD]], (default) [[CYAN]]5[[RESET]][[BOLD]]>'
89   // TREE: no viable conversion
90   // TREE:   A<
91   // TREE:     {{\[}}[[CYAN]]int &[[RESET]][[BOLD]] != [[CYAN]]int[[RESET]][[BOLD]]],
92   // TREE:     {{\[}}[[CYAN]]x[[RESET]][[BOLD]] != (default) [[CYAN]]5[[RESET]][[BOLD]]]>
93 
94   A<int**, nullptr> a2 = A<int, 3 + 1>();
95   // CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<[[CYAN]]int[[RESET]][[BOLD]], [[CYAN]]3 + 1[[RESET]][[BOLD]] aka [[CYAN]]4[[RESET]][[BOLD]]>' to 'A<[[CYAN]]int **[[RESET]][[BOLD]], [[CYAN]]nullptr[[RESET]][[BOLD]]>'
96   // TREE: no viable conversion
97   // TREE:   A<
98   // TREE:     {{\[}}[[CYAN]]int[[RESET]][[BOLD]] != [[CYAN]]int **[[RESET]][[BOLD]]],
99   // TREE:     {{\[}}[[CYAN]]3 + 1[[RESET]][[BOLD]] aka [[CYAN]]4[[RESET]][[BOLD]] != [[CYAN]]nullptr[[RESET]][[BOLD]]]>
100 }
101