]> granicus.if.org Git - clang/commitdiff
Implement DR61: Address of ambiguous bound methods should be disallowed
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 11 Jun 2013 03:56:29 +0000 (03:56 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 11 Jun 2013 03:56:29 +0000 (03:56 +0000)
DR61 affirms that expressions containing unresolved member access should
be disallowed when performing "address of" operations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183723 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/CXX/drs/dr0xx.cpp
test/CXX/expr/expr.unary/expr.unary.op/p4.cpp
test/SemaTemplate/instantiate-overload-candidates.cpp
www/cxx_dr_status.html

index 66598992d7f33857cebe850b3e6e00c9497b2edd..08e3089094527553cd206c77cf613a85b518a354 100644 (file)
@@ -8356,7 +8356,15 @@ static QualType CheckAddressOfOperand(Sema &S, ExprResult &OrigOp,
           << OrigOp.get()->getSourceRange();
         return QualType();
       }
-                  
+
+      OverloadExpr *Ovl = cast<OverloadExpr>(OrigOp.get()->IgnoreParens());
+      if (isa<UnresolvedMemberExpr>(Ovl))
+        if (!S.ResolveSingleFunctionTemplateSpecialization(Ovl)) {
+          S.Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
+            << OrigOp.get()->getSourceRange();
+          return QualType();
+        }
+
       return S.Context.OverloadTy;
     }
 
index 5ffc7516f5d61ddf1f495e2734e014c01f13955e..01b1b2aea45a92411ab7fd272206749fa9f0f699 100644 (file)
@@ -627,7 +627,7 @@ namespace dr60 { // dr60: yes
   int &n = f(k);
 }
 
-namespace dr61 { // dr61: no
+namespace dr61 { // dr61: yes
   struct X {
     static void f();
   } x;
@@ -638,8 +638,7 @@ namespace dr61 { // dr61: no
   // This is (presumably) valid, because x.f does not refer to an overloaded
   // function name.
   void (*p)() = &x.f;
-  // FIXME: This should be rejected.
-  void (*q)() = &y.f;
+  void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
 }
 
 namespace dr62 { // dr62: yes
index 06cc61074026a2f81d5cf54abdfe2986616f5368..cd55cc2441a23a87d8a69694980657adb00d3a76 100644 (file)
@@ -38,6 +38,8 @@ namespace test2 {
   };
 
   void A::test() {
-    int (A::*ptr)(int) = &(A::foo); // expected-error {{can't form member pointer of type 'int (test2::A::*)(int)' without '&' and class name}}
+    // FIXME: The error message in this case is less than clear, we can do
+    // better.
+    int (A::*ptr)(int) = &(A::foo); // expected-error {{cannot create a non-constant pointer to member function}}
   }
 }
index 7542dbd8ab9b23fea6ee050e3a67781e3e29d7b7..6b156a20a4cb4f4d3f376171dacd34cf5f594eff 100644 (file)
@@ -26,7 +26,7 @@ template<typename T> struct X {
   static T f() { T::error; } // expected-error {{has no members}}
   static T f(bool);
 };
-void (*p)() = &X<void>().f; // expected-note {{instantiation of}}
+void (*p)() = &X<void>::f; // expected-note {{instantiation of}}
 
 namespace PR13098 {
   struct A {
index 7ec46ab8b042d69547e6d65f8240b265e6ffbe21..4c43d45208f0ec1ef375ab142f265d14838fa366 100644 (file)
@@ -80,7 +80,7 @@
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#7">7</a></td>
     <td>NAD</td>
     <td>Can a class with a private virtual base class be derived from?</td>
-    <td class="none" align="center">No</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#8">8</a></td>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#61">61</a></td>
     <td>NAD</td>
     <td>Address of static member function "<TT>&amp;p-&gt;f</TT>"</td>
-    <td class="none" align="center">No</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#62">62</a></td>