p2.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. namespace N {
  3. struct X { };
  4. X operator+(X, X);
  5. void f(X); // expected-note 2 {{'N::f' declared here}}
  6. void g(X); // expected-note{{candidate function}}
  7. void test_multiadd(X x) {
  8. (void)(x + x);
  9. }
  10. }
  11. namespace M {
  12. struct Y : N::X { };
  13. }
  14. void f();
  15. void test_operator_adl(N::X x, M::Y y) {
  16. (void)(x + x);
  17. (void)(y + y);
  18. }
  19. void test_func_adl(N::X x, M::Y y) {
  20. f(x);
  21. f(y);
  22. (f)(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}}
  23. ::f(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}}
  24. }
  25. namespace N {
  26. void test_multiadd2(X x) {
  27. (void)(x + x);
  28. }
  29. }
  30. void test_func_adl_only(N::X x) {
  31. g(x);
  32. }
  33. namespace M {
  34. int g(N::X); // expected-note{{candidate function}}
  35. void test(N::X x) {
  36. g(x); // expected-error{{call to 'g' is ambiguous}}
  37. int i = (g)(x);
  38. int g(N::X);
  39. g(x); // okay; calls locally-declared function, no ADL
  40. }
  41. }
  42. void test_operator_name_adl(N::X x) {
  43. (void)operator+(x, x);
  44. }
  45. struct Z { };
  46. int& f(Z);
  47. namespace O {
  48. char &f();
  49. void test_global_scope_adl(Z z) {
  50. {
  51. int& ir = f(z);
  52. }
  53. }
  54. }
  55. extern "C" {
  56. struct L { int x; };
  57. }
  58. void h(L); // expected-note{{candidate function}}
  59. namespace P {
  60. void h(L); // expected-note{{candidate function}}
  61. void test_transparent_context_adl(L l) {
  62. {
  63. h(l); // expected-error {{call to 'h' is ambiguous}}
  64. }
  65. }
  66. }
  67. namespace test5 {
  68. namespace NS {
  69. struct A;
  70. void foo(void (*)(A&));
  71. }
  72. void bar(NS::A& a);
  73. void test() {
  74. foo(&bar);
  75. }
  76. }
  77. // PR6762: __builtin_va_list should be invisible to ADL on all platforms.
  78. void test6_function(__builtin_va_list &argv);
  79. namespace test6 {
  80. void test6_function(__builtin_va_list &argv);
  81. void test() {
  82. __builtin_va_list args;
  83. test6_function(args);
  84. }
  85. }
  86. // PR13682: we might need to instantiate class temploids.
  87. namespace test7 {
  88. namespace inner {
  89. class A {};
  90. void test7_function(A &);
  91. }
  92. template <class T> class B : public inner::A {};
  93. void test(B<int> &ref) {
  94. test7_function(ref);
  95. }
  96. }
  97. // Like test7, but ensure we don't complain if the type is properly
  98. // incomplete.
  99. namespace test8 {
  100. template <class T> class B;
  101. void test8_function(B<int> &);
  102. void test(B<int> &ref) {
  103. test8_function(ref);
  104. }
  105. }