[clang] [Clang][C++2d] Implement defaulted postfix increment and decrement operators (P3668R4) (PR #229560)

Muhammad Bassiouni via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 18:52:50 PDT 2026


================
@@ -3311,7 +3306,23 @@ FunctionDecl::getDefaultedFunctionKind() const {
       return CXXSpecialMemberKind::Destructor;
   }
 
-  switch (getDeclName().getCXXOverloadedOperator()) {
+  switch (OverloadedOperatorKind OO =
+              getDeclName().getCXXOverloadedOperator()) {
+  case OO_PlusPlus:
+  case OO_MinusMinus: {
+    // Only the postfix forms can be defaulted. They are distinguished from the
+    // prefix forms by their trailing 'int' parameter, so they have exactly two
+    // parameters once the implicit object parameter (if any) is counted.
+    unsigned NumParams = getNumParams();
+    if (const auto *MD = dyn_cast<CXXMethodDecl>(this);
+        MD && MD->isImplicitObjectMemberFunction())
+      ++NumParams;
----------------
bassiounix wrote:

If you find an existing util like this which I can use, please let me know!

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


More information about the cfe-commits mailing list