[clang] [HLSL] Disable implicit constructors for user-defined structs/classes (PR #194989)

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Thu May 7 14:56:27 PDT 2026


================
@@ -1013,17 +1015,18 @@ class CXXRecordDecl : public RecordDecl {
   /// assignment operator or if any existing special member function inhibits
   /// this.
   bool needsImplicitMoveAssignment() const {
+    // In HLSL, only built-in records like resources classes can have
+    // constructors and overloadable operators.
+    if (getLangOpts().HLSL && !hasUserProvidedSpecialMembers())
+      return false;
+
     return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
            !hasUserDeclaredCopyConstructor() &&
            !hasUserDeclaredCopyAssignment() &&
-           !hasUserDeclaredMoveConstructor() && !hasUserDeclaredDestructor() &&
-           (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()) &&
-           // In HLSL, only built-in records like resources classes can have
-           // constructors.
-           (!getLangOpts().HLSL ||
-            (isLambda() && lambdaIsDefaultConstructibleAndAssignable()) ||
-            hasUserProvidedSpecialMembers());
-  }
+           !hasUserDeclaredMoveConstructor() &&
+           !hasUserDeclaredDestructor() &&
+           (!isLambda() || lambdaIsDefaultConstructibleAndAssignable());
----------------
bob80905 wrote:

You've removed the `isLambda()` condition from functions in charge of implicit Default/Copy/Move Constructors, and Copy assignment, but left this isLambda function for this implicit move assignment. Is this intentional, or should we remove the call to the lambda functions here, or reinstate the lambda checks for the functions mentioned above?

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


More information about the cfe-commits mailing list