Clang Project

clang_source_code/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3template <class T> T* f(int); // #1 
4template <class T, class U> T& f(U); // #2 
5
6void g() {
7  int *ip = f<int>(1); // calls #1
8}
9
10template<typename T>
11struct identity {
12  typedef T type;
13};
14
15template <class T> 
16  T* f2(int, typename identity<T>::type = 0);
17template <class T, class U> 
18  T& f2(U, typename identity<T>::type = 0);
19
20void g2() {
21  int* ip = f2<int>(1);
22}
23
24template<class T, class U> struct A { };
25
26template<class T, class U> inline int *f3( U, A<U,T>* p = 0 ); // #1 expected-note{{candidate function [with T = int, U = int]}}
27template<         class U> inline float *f3( U, A<U,U>* p = 0 ); // #2 expected-note{{candidate function [with U = int]}}
28
29void g3() {
30   float *fp = f3<int>( 42, (A<int,int>*)0 );  // Ok, picks #2.
31   f3<int>( 42 );                  // expected-error{{call to 'f3' is ambiguous}}
32   
33}
34
35namespace PR9006 {
36  struct X {
37    template <class Get>
38    int &f(char const* name, Get fget, char const* docstr = 0);
39  
40    template <class Get, class Set>
41    float &f(char const* name, Get fget, Set fset, char const* docstr = 0);
42  };
43
44  void test(X x) {
45    int &ir = x.f("blah", 0, "blah");
46  }
47}
48