[PATCH] D6700: Diagnose UnresolvedLookupExprs that resolve to instance members in static methods

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 17:59:12 PDT 2015


rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM


================
Comment at: lib/Sema/TreeTransform.h:9131
@@ -9130,2 +9130,3 @@
   // it's a normal declaration name.
-  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
+  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
+    // If an UnresolvedLookupExpr resolved to an instance member, that's an
----------------
Please also add a test for the case with explicit template arguments, something like:

  struct X {
    template<typename> void f();
    template<typename T, typename T::type = 0> static void f();
    template<typename T> void g() { (void)f<T>; }
  };
  void h(X x) { x.g<int>(); }

... should do the trick. (This already seems to work.)

================
Comment at: test/SemaCXX/using-decl-1.cpp:340-349
@@ +339,12 @@
+  static void m_fn1() {
+    // expected-error at +1 {{invalid use of member 'field' in static member function}}
+    (void)field;
+    // expected-error at +1 {{invalid use of member 'field' in static member function}}
+    (void)&field;
+    // expected-error at +1 {{call to non-static member function without an object argument}}
+    (void)method;
+    // expected-error at +1 {{call to non-static member function without an object argument}}
+    (void)&method;
+    // expected-error at +1 {{call to non-static member function without an object argument}}
+    method();
+  }
----------------
Please also add tests that we don't reject the corresponding address-of-member cases.


http://reviews.llvm.org/D6700





More information about the cfe-commits mailing list