xref: /llvm-project/clang/test/SemaTemplate/implicit-instantiation-1.cpp (revision 8fbe78f6fc7b41d1a4228c126fcb522131150518)
1*8fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s
2412190b0SDouglas Gregor template<typename T, typename U>
3412190b0SDouglas Gregor struct X {
fX4412190b0SDouglas Gregor   T f(T x, U y) { return x + y; }
5412190b0SDouglas Gregor 
gX6412190b0SDouglas Gregor   unsigned g(T x, U y) { return sizeof(f(x, y)); }
7412190b0SDouglas Gregor };
8412190b0SDouglas Gregor 
test(X<int,int> * xii,X<int *,int> * xpi,X<int,int * > * xip)9412190b0SDouglas Gregor void test(X<int, int> *xii, X<int*, int> *xpi, X<int, int*> *xip) {
10412190b0SDouglas Gregor   (void)xii->f(1, 2);
11412190b0SDouglas Gregor   (void)xpi->f(0, 2);
12412190b0SDouglas Gregor   (void)sizeof(xip->f(2, 0)); // okay: does not instantiate
13412190b0SDouglas Gregor   (void)xip->g(2, 0); // okay: does not instantiate
14412190b0SDouglas Gregor }
15412190b0SDouglas Gregor 
164adbc6d9SDouglas Gregor template<typename T, typename U>
add(T t,U u)174adbc6d9SDouglas Gregor T add(T t, U u) {
184adbc6d9SDouglas Gregor   return t + u; // expected-error{{invalid operands}}
194adbc6d9SDouglas Gregor }
204adbc6d9SDouglas Gregor 
test_add(char * cp,int i,int * ip)214adbc6d9SDouglas Gregor void test_add(char *cp, int i, int *ip) {
224adbc6d9SDouglas Gregor   char* cp2 = add(cp, i);
234adbc6d9SDouglas Gregor   add(cp, cp); // expected-note{{instantiation of}}
244adbc6d9SDouglas Gregor   (void)sizeof(add(ip, ip));
254adbc6d9SDouglas Gregor }
26