121d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s
221d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin
321d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin// C++98 [basic.lookup.classref]p1:
421d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   In a class member access expression (5.2.5), if the . or -> token is
521d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   immediately followed by an identifier followed by a <, the identifier must
621d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   be looked up to determine whether the < is the beginning of a template
721d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   argument list (14.2) or a less-than operator. The identifier is first
821d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   looked up in the class of the object expression. If the identifier is not
921d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   found, it is then looked up in the context of the entire postfix-expression
1021d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   and shall name a class or function template. If the lookup in the class of
1121d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   the object expression finds a template, the name is also looked up in the
1221d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//   context of the entire postfix-expression and
1321d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//    -- if the name is not found, the name found in the class of the object
1421d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//       expression is used, otherwise
1521d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//    -- if the name is found in the context of the entire postfix-expression
1621d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//       and does not name a class template, the name found in the class of the
1721d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//       object expression is used, otherwise
1821d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//    -- if the name found is a class template, it must refer to the same
1921d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//       entity as the one found in the class of the object expression,
2021d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin//       otherwise the program is ill-formed.
2121d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin
2221d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin// From PR 7247
2321d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskintemplate<typename T>
2421d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskinstruct set{};  // expected-note{{lookup from the current scope refers here}}
2521d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskinstruct Value {
2621d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  template<typename T>
2721d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  void set(T value) {}  // expected-note{{lookup in the object type 'Value' refers here}}
2821d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin
2921d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  void resolves_to_same() {
3021d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    Value v;
3121d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    v.set<double>(3.2);
3221d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  }
3321d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin};
3421d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskinvoid resolves_to_different() {
3521d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  {
3621d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    Value v;
3721d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    // The fact that the next line is a warning rather than an error is an
3821d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    // extension.
392fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    v.set<double>(3.2);  // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
4021d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  }
4121d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  {
4221d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    int set;  // Non-template.
4321d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    Value v;
4421d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin    v.set<double>(3.2);
4521d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin  }
4621d07e499e108752c9d63d7418f7d9b485f4e0e6Jeffrey Yasskin}
47a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor
48a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregornamespace rdar9915664 {
49a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  struct A {
50a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor    template<typename T> void a();
51a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  };
52a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor
53a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  struct B : A { };
54a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor
55a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  struct C : A { };
56a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor
57a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  struct D : B, C {
58a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor    A &getA() { return static_cast<B&>(*this); }
59a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor
60a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor    void test_a() {
61a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor      getA().a<int>();
62a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor    }
63a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor  };
64a6d1e7623a9b7bd60779275c42827951a892993bDouglas Gregor}
655a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor
665a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregornamespace PR11856 {
675a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  template<typename T> T end(T);
685a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor
695a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  template <typename T>
705a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  void Foo() {
715a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    T it1;
725a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    if (it1->end < it1->end) {
735a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    }
745a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  }
755a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor
765a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  template<typename T> T *end(T*);
775a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor
785a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  class X { };
795a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  template <typename T>
805a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  void Foo2() {
815a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    T it1;
825a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    if (it1->end < it1->end) {
835a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    }
845a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor
855a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    X *x;
865a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    if (x->end < 7) {  // expected-error{{no member named 'end' in 'PR11856::X'}}
875a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor    }
885a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor  }
895a7a5bb20904a1d34255b772c87b930e798f59a8Douglas Gregor}
90