xref: /llvm-project/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p4.cpp (revision c9e46219f38da5c3fbfe41012173dc893516826e)
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
3 
4 namespace PR8598 {
5   template<class T> struct identity { typedef T type; };
6 
7   template<class T, class C>
f(T C::*,typename identity<T>::type *)8   void f(T C::*, typename identity<T>::type*){}
9 
fPR8598::X10   struct X { void f() {}; };
11 
g()12   void g() { (f)(&X::f, 0); }
13 }
14 
15 namespace PR12132 {
fun(const int * const S::* member)16   template<typename S> void fun(const int* const S::* member) {}
17   struct A { int* x; };
foo()18   void foo() {
19     fun(&A::x);
20   }
21   struct B { char* x; };
bar()22   void bar() {
23     fun(&B::x);
24     // expected-error@-1 {{no matching function for call to 'fun'}}
25     // expected-note@-9  {{candidate template ignored: could not match 'const int' against 'char'}}
26   }
27 }
28 
29 #if __cplusplus > 201402L
30 namespace noexcept_conversion {
31   template<typename R> void foo(R());
32   template<typename R> void bar(R()) = delete;
bar(R ()noexcept)33   template<typename R> void bar(R() noexcept) {}
f()34   void f() throw() {
35     foo(&f);
36     bar(&f);
37   }
38   // There is no corresponding rule for references.
39   // We consider this to be a defect, and allow deduction to succeed in this
40   // case. FIXME: Check this should be accepted once the DR is resolved.
41   template<typename R> void baz(R(&)());
g()42   void g() {
43     baz(f);
44   }
45 
46   // But there is one for member pointers.
47   template<typename R, typename C, typename ...A> void quux(R (C::*)(A...));
fnoexcept_conversion::Q48   struct Q { void f(int, char) noexcept { quux(&Q::f); } };
49 
50   void g1() noexcept;
51   void g2();
52   template <class T> int h(T *, T *); // expected-note {{deduced conflicting types for parameter 'T' ('void () noexcept' vs. 'void ()')}}
53   int x = h(g1, g2); // expected-error {{no matching function}}
54 
55   // We consider it a defect that deduction does not support the following.
56   // FIXME: Check that the defect is resolved as we expect.
57   template<bool B> int i(void () noexcept(B));
58   int i1 = i(g1);
59   int i2 = i(g2);
60 }
61 #endif
62