blob: 44954ed881abda822e6854e346b16f2c78fbeb42 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor37b372b2009-08-20 22:52:58 +00002
3struct X {
Douglas Gregor6b906862009-08-21 00:16:32 +00004 template<typename T> T& f0(T);
5
6 void g0(int i, double d) {
7 int &ir = f0(i);
8 double &dr = f0(d);
9 }
10
11 template<typename T> T& f1(T);
12 template<typename T, typename U> U& f1(T, U);
13
14 void g1(int i, double d) {
15 int &ir1 = f1(i);
16 int &ir2 = f1(d, i);
17 int &ir3 = f1(i, i);
18 }
Douglas Gregor37b372b2009-08-20 22:52:58 +000019};
Douglas Gregor6b906862009-08-21 00:16:32 +000020
21void test_X_f0(X x, int i, float f) {
22 int &ir = x.f0(i);
23 float &fr = x.f0(f);
24}
25
26void test_X_f1(X x, int i, float f) {
27 int &ir1 = x.f1(i);
28 int &ir2 = x.f1(f, i);
29 int &ir3 = x.f1(i, i);
Douglas Gregordec06662009-08-21 18:42:58 +000030}
Douglas Gregor15612482009-08-21 23:32:45 +000031
32void test_X_f0_address() {
33 int& (X::*pm1)(int) = &X::f0;
34 float& (X::*pm2)(float) = &X::f0;
35}
36
37void test_X_f1_address() {
38 int& (X::*pm1)(int) = &X::f1;
39 float& (X::*pm2)(float) = &X::f1;
40 int& (X::*pm3)(float, int) = &X::f1;
41}
Douglas Gregord83d0402009-08-22 00:34:47 +000042
Douglas Gregorf328a282009-08-31 21:16:32 +000043void test_X_f0_explicit(X x, int i, long l) {
44 int &ir1 = x.f0<int>(i);
45 int &ir2 = x.f0<>(i);
Douglas Gregorc4bf26f2009-09-01 00:37:14 +000046 long &il1 = x.f0<long>(i);
Douglas Gregorf328a282009-08-31 21:16:32 +000047}
48
Douglas Gregord83d0402009-08-22 00:34:47 +000049// PR4608
50class A { template <class x> x a(x z) { return z+y; } int y; };
Douglas Gregor2dd078a2009-09-02 22:59:36 +000051
Douglas Gregor3734c212009-11-07 17:23:56 +000052// PR5419
53struct Functor {
54 template <typename T>
55 bool operator()(const T& v) const {
56 return true;
57 }
58};
59
60void test_Functor(Functor f) {
61 f(1);
62}
Douglas Gregor03c57052009-11-17 05:17:33 +000063
64// Instantiation on ->
65template<typename T>
66struct X1 {
67 template<typename U> U& get();
68};
69
70template<typename T> struct X2; // expected-note{{here}}
71
72void test_incomplete_access(X1<int> *x1, X2<int> *x2) {
73 float &fr = x1->get<float>();
74 (void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}}
75}
Douglas Gregor6d3e6272010-02-05 19:54:12 +000076
77// Instantiation of template template parameters in a member function
78// template.
79namespace TTP {
80 template<int Dim> struct X {
81 template<template<class> class M, class T> void f(const M<T>&);
82 };
83
84 template<typename T> struct Y { };
85
86 void test_f(X<3> x, Y<int> y) { x.f(y); }
87}
Douglas Gregor3e1274f2010-06-16 21:09:37 +000088
89namespace PR7387 {
90 template <typename T> struct X {};
91
92 template <typename T1> struct S {
93 template <template <typename> class TC> void foo(const TC<T1>& arg);
94 };
95
96 template <typename T1> template <template <typename> class TC>
97 void S<T1>::foo(const TC<T1>& arg) {}
98
99 void test(const X<int>& x) {
100 S<int> s;
101 s.foo(x);
102 }
103}