[PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 9 15:10:47 PDT 2015


rsmith added inline comments.

================
Comment at: lib/Sema/SemaExpr.cpp:10246-10253
@@ -10245,1 +10245,10 @@
+
+    if (RHS.get()->getType() == Context.OverloadTy) {
+      // As a set of extensions to C, we support overloading on functions. These
+      // functions need to be resolved here.
+      DeclAccessPair DAP;
+      if (FunctionDecl *FD = ResolveAddressOfOverloadedFunction(
+              RHS.get(), LHS.get()->getType(), /*Complain=*/false, DAP))
+        RHS = FixOverloadedFunctionReference(RHS.get(), DAP, FD);
+    }
   }
----------------
Converting the RHS to the type of the LHS seems to only be appropriate for simple assignment operators, not for arbitrary binary operators.

================
Comment at: lib/Sema/SemaInit.cpp:4978-4990
@@ -4977,1 +4977,15 @@
 
+    // As an extension, C can have overloaded functions. We need to add the
+    // address resolution step.
+    if (Initializer->getType() == Context.OverloadTy) {
+      bool MultipleCandidates;
+      DeclAccessPair DAP;
+      if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+              Initializer, DestType, false, DAP, &MultipleCandidates)) {
+        AddAddressOverloadResolutionStep(FD, DAP, MultipleCandidates);
+      } else {
+        SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
+        return;
+      }
+    }
+
----------------
It would seem better to handle this in the assignment rules rather than duplicating it between here and the binary operator case.


http://reviews.llvm.org/D13607





More information about the cfe-commits mailing list