p2.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. namespace Ints {
  3. int zero = 0; // expected-note {{candidate found by name lookup is 'Ints::zero'}}
  4. void f(int); // expected-note 3 {{candidate function}}
  5. void g(int);
  6. }
  7. namespace Floats {
  8. float zero = 0.0f; // expected-note {{candidate found by name lookup is 'Floats::zero'}}
  9. void f(float); // expected-note 3 {{candidate function}}
  10. void g(float);
  11. }
  12. namespace Numbers {
  13. using namespace Ints;
  14. using namespace Floats;
  15. }
  16. void test() {
  17. int i = Ints::zero;
  18. Ints::f(i);
  19. float f = Floats::zero;
  20. Floats::f(f);
  21. double n = Numbers::zero; // expected-error {{reference to 'zero' is ambiguous}}
  22. Numbers::f(n); // expected-error{{call to 'f' is ambiguous}}
  23. Numbers::f(i);
  24. Numbers::f(f);
  25. }
  26. namespace Numbers {
  27. struct Number { // expected-note 2 {{candidate}}
  28. explicit Number(double d) : d(d) {}
  29. double d;
  30. };
  31. Number zero(0.0f);
  32. void g(Number); // expected-note 2{{passing argument to parameter here}}
  33. }
  34. void test2() {
  35. Numbers::Number n = Numbers::zero;
  36. Numbers::f(n); // expected-error {{no matching function for call to 'f'}}
  37. Numbers::g(n);
  38. }
  39. namespace Numbers2 {
  40. using Numbers::f;
  41. using Numbers::g;
  42. }
  43. void test3() {
  44. Numbers::Number n = Numbers::zero;
  45. Numbers2::f(n); // expected-error {{no matching function for call to 'f'}}
  46. Numbers2::g(n);
  47. int i = Ints::zero;
  48. Numbers2::f(i);
  49. Numbers2::g(i); // expected-error {{no viable conversion from 'int' to 'Numbers::Number'}}
  50. float f = Floats::zero;
  51. Numbers2::f(f);
  52. Numbers2::g(f); // expected-error {{no viable conversion from 'float' to 'Numbers::Number'}}
  53. }
  54. namespace inline_ns {
  55. int x; // expected-note 2{{found}}
  56. inline namespace A { // expected-warning {{C++11}}
  57. int x; // expected-note 2{{found}}
  58. int y; // expected-note 2{{found}}
  59. }
  60. int y; // expected-note 2{{found}}
  61. int k1 = x + y; // expected-error 2{{ambiguous}}
  62. int k2 = inline_ns::x + inline_ns::y; // expected-error 2{{ambiguous}}
  63. }