ms-if-exists.cpp 681 B

123456789101112131415161718192021222324252627282930
  1. // RUN: %clang_cc1 -x c++ -fms-extensions -fsyntax-only -emit-pch -o %t %s
  2. // RUN: %clang_cc1 -x c++ -fms-extensions -fsyntax-only -include-pch %t %s -verify
  3. #ifndef HEADER
  4. #define HEADER
  5. template<typename T>
  6. void f(T t) {
  7. __if_exists(T::foo) {
  8. { }
  9. t.foo();
  10. }
  11. __if_not_exists(T::bar) {
  12. int *i = t;
  13. { }
  14. }
  15. }
  16. #else
  17. struct HasFoo {
  18. void foo();
  19. };
  20. struct HasBar {
  21. void bar(int);
  22. void bar(float);
  23. };
  24. template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f<HasFoo>' requested here}}
  25. // expected-error@14{{no viable conversion from 'HasFoo' to 'int *'}}
  26. template void f(HasBar);
  27. #endif