implicit-instantiation-1.cpp 664 B

12345678910111213141516171819202122232425
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T, typename U>
  3. struct X {
  4. T f(T x, U y) { return x + y; }
  5. unsigned g(T x, U y) { return sizeof(f(x, y)); }
  6. };
  7. void test(X<int, int> *xii, X<int*, int> *xpi, X<int, int*> *xip) {
  8. (void)xii->f(1, 2);
  9. (void)xpi->f(0, 2);
  10. (void)sizeof(xip->f(2, 0)); // okay: does not instantiate
  11. (void)xip->g(2, 0); // okay: does not instantiate
  12. }
  13. template<typename T, typename U>
  14. T add(T t, U u) {
  15. return t + u; // expected-error{{invalid operands}}
  16. }
  17. void test_add(char *cp, int i, int *ip) {
  18. char* cp2 = add(cp, i);
  19. add(cp, cp); // expected-note{{instantiation of}}
  20. (void)sizeof(add(ip, ip));
  21. }