xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/member-function-template.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct X {
4*f4a2713aSLionel Sambuc   template<typename T> T& f0(T);
5*f4a2713aSLionel Sambuc 
g0X6*f4a2713aSLionel Sambuc   void g0(int i, double d) {
7*f4a2713aSLionel Sambuc     int &ir = f0(i);
8*f4a2713aSLionel Sambuc     double &dr = f0(d);
9*f4a2713aSLionel Sambuc   }
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc   template<typename T> T& f1(T);
12*f4a2713aSLionel Sambuc   template<typename T, typename U> U& f1(T, U);
13*f4a2713aSLionel Sambuc 
g1X14*f4a2713aSLionel Sambuc   void g1(int i, double d) {
15*f4a2713aSLionel Sambuc     int &ir1 = f1(i);
16*f4a2713aSLionel Sambuc     int &ir2 = f1(d, i);
17*f4a2713aSLionel Sambuc     int &ir3 = f1(i, i);
18*f4a2713aSLionel Sambuc   }
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
test_X_f0(X x,int i,float f)21*f4a2713aSLionel Sambuc void test_X_f0(X x, int i, float f) {
22*f4a2713aSLionel Sambuc   int &ir = x.f0(i);
23*f4a2713aSLionel Sambuc   float &fr = x.f0(f);
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc 
test_X_f1(X x,int i,float f)26*f4a2713aSLionel Sambuc void test_X_f1(X x, int i, float f) {
27*f4a2713aSLionel Sambuc   int &ir1 = x.f1(i);
28*f4a2713aSLionel Sambuc   int &ir2 = x.f1(f, i);
29*f4a2713aSLionel Sambuc   int &ir3 = x.f1(i, i);
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
test_X_f0_address()32*f4a2713aSLionel Sambuc void test_X_f0_address() {
33*f4a2713aSLionel Sambuc   int& (X::*pm1)(int) = &X::f0;
34*f4a2713aSLionel Sambuc   float& (X::*pm2)(float) = &X::f0;
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
test_X_f1_address()37*f4a2713aSLionel Sambuc void test_X_f1_address() {
38*f4a2713aSLionel Sambuc   int& (X::*pm1)(int) = &X::f1;
39*f4a2713aSLionel Sambuc   float& (X::*pm2)(float) = &X::f1;
40*f4a2713aSLionel Sambuc   int& (X::*pm3)(float, int) = &X::f1;
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
test_X_f0_explicit(X x,int i,long l)43*f4a2713aSLionel Sambuc void test_X_f0_explicit(X x, int i, long l) {
44*f4a2713aSLionel Sambuc   int &ir1 = x.f0<int>(i);
45*f4a2713aSLionel Sambuc   int &ir2 = x.f0<>(i);
46*f4a2713aSLionel Sambuc   long &il1 = x.f0<long>(i);
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // PR4608
a(x z)50*f4a2713aSLionel Sambuc class A { template <class x> x a(x z) { return z+y; } int y; };
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc // PR5419
53*f4a2713aSLionel Sambuc struct Functor {
54*f4a2713aSLionel Sambuc   template <typename T>
operator ()Functor55*f4a2713aSLionel Sambuc   bool operator()(const T& v) const {
56*f4a2713aSLionel Sambuc     return true;
57*f4a2713aSLionel Sambuc   }
58*f4a2713aSLionel Sambuc };
59*f4a2713aSLionel Sambuc 
test_Functor(Functor f)60*f4a2713aSLionel Sambuc void test_Functor(Functor f) {
61*f4a2713aSLionel Sambuc   f(1);
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc // Instantiation on ->
65*f4a2713aSLionel Sambuc template<typename T>
66*f4a2713aSLionel Sambuc struct X1 {
67*f4a2713aSLionel Sambuc   template<typename U> U& get();
68*f4a2713aSLionel Sambuc };
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc template<typename T> struct X2; // expected-note{{here}}
71*f4a2713aSLionel Sambuc 
test_incomplete_access(X1<int> * x1,X2<int> * x2)72*f4a2713aSLionel Sambuc void test_incomplete_access(X1<int> *x1, X2<int> *x2) {
73*f4a2713aSLionel Sambuc   float &fr = x1->get<float>();
74*f4a2713aSLionel Sambuc   (void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}}
75*f4a2713aSLionel Sambuc }
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc // Instantiation of template template parameters in a member function
78*f4a2713aSLionel Sambuc // template.
79*f4a2713aSLionel Sambuc namespace TTP {
80*f4a2713aSLionel Sambuc   template<int Dim> struct X {
81*f4a2713aSLionel Sambuc     template<template<class> class M, class T> void f(const M<T>&);
82*f4a2713aSLionel Sambuc   };
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc   template<typename T> struct Y { };
85*f4a2713aSLionel Sambuc 
test_f(X<3> x,Y<int> y)86*f4a2713aSLionel Sambuc   void test_f(X<3> x, Y<int> y) { x.f(y); }
87*f4a2713aSLionel Sambuc }
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc namespace PR7387 {
90*f4a2713aSLionel Sambuc   template <typename T> struct X {};
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc   template <typename T1> struct S {
93*f4a2713aSLionel Sambuc     template <template <typename> class TC> void foo(const TC<T1>& arg);
94*f4a2713aSLionel Sambuc   };
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc   template <typename T1> template <template <typename> class TC>
foo(const TC<T1> & arg)97*f4a2713aSLionel Sambuc   void S<T1>::foo(const TC<T1>& arg) {}
98*f4a2713aSLionel Sambuc 
test(const X<int> & x)99*f4a2713aSLionel Sambuc   void test(const X<int>& x) {
100*f4a2713aSLionel Sambuc     S<int> s;
101*f4a2713aSLionel Sambuc     s.foo(x);
102*f4a2713aSLionel Sambuc   }
103*f4a2713aSLionel Sambuc }
104