[clang] [HLSL] Remove support for constructors for user defined structs (PR #190089)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 12:42:20 PDT 2026


================
@@ -759,19 +759,33 @@ class CXXRecordDecl : public RecordDecl {
            needsImplicitDefaultConstructor();
   }
 
+  // Used by HLSL to determine if implicit constructors and operators should
+  // be allowed for structs. This is required for HLSL's resource classes.
+  /// Determines whether this class has any user provided special members.
+  bool hasUserProvidedSpecialMembers() const {
+    return data().UserDeclaredSpecialMembers &
+               (SMF_MoveConstructor | SMF_MoveAssignment | SMF_Destructor |
+                SMF_CopyAssignment | SMF_CopyConstructor) ||
+           data().UserDeclaredConstructor ||
+           data().UserProvidedDefaultConstructor;
+  }
+
   /// Determine if we need to declare a default constructor for
   /// this class.
   ///
   /// This value is used for lazy creation of default constructors.
   bool needsImplicitDefaultConstructor() const {
-    return (!data().UserDeclaredConstructor &&
-            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
-            (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) ||
-           // FIXME: Proposed fix to core wording issue: if a class inherits
-           // a default constructor and doesn't explicitly declare one, one
-           // is declared implicitly.
-           (data().HasInheritedDefaultConstructor &&
-            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor));
+    return ((!data().UserDeclaredConstructor &&
+             !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
+             (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) ||
+            // FIXME: Proposed fix to core wording issue: if a class inherits
+            // a default constructor and doesn't explicitly declare one, one
+            // is declared implicitly.
+            (data().HasInheritedDefaultConstructor &&
+             !(data().DeclaredSpecialMembers & SMF_DefaultConstructor))) &&
+           (!getLangOpts().HLSL ||
+            (isLambda() && lambdaIsDefaultConstructibleAndAssignable()) ||
+            hasUserProvidedSpecialMembers());
----------------
hekota wrote:

Is `hasUserProvidedSpecialMember()` used here to determine if a decl is a resource record? Based on the fact that resource records (and related types) have a default constructor and copy operator explicitly defined in `HLSLExternalSemaSource`? If it is, then I think it would be better to replace with `IsImplicit()`, which means the decl was defined in `HLSLExternalSemaSource` and not in a user code.

Same for all the other `needsImplicit*` functions in this file that were edider.

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


More information about the cfe-commits mailing list