[clang] [clang] Improve checking of operator functions (PR #131777)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 19 11:26:19 PDT 2025


================
@@ -4120,6 +4121,28 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
     }
   }
 
+  // If the template is an operator function template, check that the
+  // resulting specialization is a valid operator function.
+  switch (Specialization->getOverloadedOperator()) {
+  case OO_None:
+  case OO_New:
+  case OO_Array_New:
+  case OO_Delete:
+  case OO_Array_Delete:
+    break;
+
+  default:
+    // SFINAE does not apply at this point in the instantiation process.
+    // Push a new CodeSynthesisContext to briefly re-enable it here.
+    InstantiatingTemplate Inst(
+        *this, Info.getLocation(), FunctionTemplate, DeducedArgs,
+        CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
+    if (Inst.isInvalid())
+      return TemplateDeductionResult::InstantiationDepth;
+    if (CheckOverloadedOperatorParams(Specialization))
+      return TemplateDeductionResult::SubstitutionFailure;
----------------
offsetof wrote:

Sure. Added a comment with the reference.

https://github.com/llvm/llvm-project/pull/131777


More information about the cfe-commits mailing list