[cfe-commits] r165763 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/FixIt/fixit.cpp test/FixIt/no-fixit.cpp

David Blaikie dblaikie at gmail.com
Thu Oct 11 15:55:08 PDT 2012


Author: dblaikie
Date: Thu Oct 11 17:55:07 2012
New Revision: 165763

URL: http://llvm.org/viewvc/llvm-project?rev=165763&view=rev
Log:
Provide a fixit when taking the address of an unqualified member function.

This only applies if the type has a name. (we could potentially do something
crazy with decltype in C++11 to qualify members of unnamed types but that
seems excessive)

It might be nice to also suggest a fixit for "&this->i", "&foo->i",
and "&foo.i" but those expressions produce 'bound' member functions that have
a different AST representation & make error recovery a little trickier. Left
as future work.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/FixIt/fixit.cpp
    cfe/trunk/test/FixIt/no-fixit.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=165763&r1=165762&r2=165763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 11 17:55:07 2012
@@ -8056,8 +8056,16 @@
 
     // The method was named without a qualifier.
     } else if (!DRE->getQualifier()) {
-      S.Diag(OpLoc, diag::err_unqualified_pointer_member_function)
-        << op->getSourceRange();
+      if (MD->getParent()->getName().empty())
+        S.Diag(OpLoc, diag::err_unqualified_pointer_member_function)
+          << op->getSourceRange();
+      else {
+        SmallString<32> Str;
+        StringRef Qual = (MD->getParent()->getName() + "::").toStringRef(Str);
+        S.Diag(OpLoc, diag::err_unqualified_pointer_member_function)
+          << op->getSourceRange()
+          << FixItHint::CreateInsertion(op->getSourceRange().getBegin(), Qual);
+      }
     }
 
     return S.Context.getMemberPointerType(op->getType(),

Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=165763&r1=165762&r2=165763&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Thu Oct 11 17:55:07 2012
@@ -292,3 +292,10 @@
     //(void)(&t<S<int>>==p);
   }
 }
+
+class foo {
+  static void test() {
+    (void)&i; // expected-error{{must explicitly qualify name of member function when taking its address}}
+  }
+  int i();
+};

Modified: cfe/trunk/test/FixIt/no-fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/no-fixit.cpp?rev=165763&r1=165762&r2=165763&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/no-fixit.cpp (original)
+++ cfe/trunk/test/FixIt/no-fixit.cpp Thu Oct 11 17:55:07 2012
@@ -5,3 +5,9 @@
 // CHECK-NOT: fix-it:
 
 template<template<typename> +> void func();
+
+struct {
+  void i() {
+    (void)&i;
+  }
+} x;





More information about the cfe-commits mailing list