p1.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s
  2. // C++98 [basic.lookup.classref]p1:
  3. // In a class member access expression (5.2.5), if the . or -> token is
  4. // immediately followed by an identifier followed by a <, the identifier must
  5. // be looked up to determine whether the < is the beginning of a template
  6. // argument list (14.2) or a less-than operator. The identifier is first
  7. // looked up in the class of the object expression. If the identifier is not
  8. // found, it is then looked up in the context of the entire postfix-expression
  9. // and shall name a class or function template. If the lookup in the class of
  10. // the object expression finds a template, the name is also looked up in the
  11. // context of the entire postfix-expression and
  12. // -- if the name is not found, the name found in the class of the object
  13. // expression is used, otherwise
  14. // -- if the name is found in the context of the entire postfix-expression
  15. // and does not name a class template, the name found in the class of the
  16. // object expression is used, otherwise
  17. // -- if the name found is a class template, it must refer to the same
  18. // entity as the one found in the class of the object expression,
  19. // otherwise the program is ill-formed.
  20. // From PR 7247
  21. template<typename T>
  22. struct set{}; // expected-note{{lookup from the current scope refers here}}
  23. struct Value {
  24. template<typename T>
  25. void set(T value) {} // expected-note{{lookup in the object type 'Value' refers here}}
  26. void resolves_to_same() {
  27. Value v;
  28. v.set<double>(3.2);
  29. }
  30. };
  31. void resolves_to_different() {
  32. {
  33. Value v;
  34. // The fact that the next line is a warning rather than an error is an
  35. // extension.
  36. v.set<double>(3.2); // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
  37. }
  38. {
  39. int set; // Non-template.
  40. Value v;
  41. v.set<double>(3.2);
  42. }
  43. }
  44. namespace rdar9915664 {
  45. struct A {
  46. template<typename T> void a();
  47. };
  48. struct B : A { };
  49. struct C : A { };
  50. struct D : B, C {
  51. A &getA() { return static_cast<B&>(*this); }
  52. void test_a() {
  53. getA().a<int>();
  54. }
  55. };
  56. }
  57. namespace PR11856 {
  58. template<typename T> T end(T);
  59. template <typename T>
  60. void Foo() {
  61. T it1;
  62. if (it1->end < it1->end) {
  63. }
  64. }
  65. template<typename T> T *end(T*);
  66. class X { };
  67. template <typename T>
  68. void Foo2() {
  69. T it1;
  70. if (it1->end < it1->end) {
  71. }
  72. X *x;
  73. if (x->end < 7) { // expected-error{{no member named 'end' in 'PR11856::X'}}
  74. }
  75. }
  76. }