[clang] [DebugInfo] Ignore delegating constructors in constructor homing. (PR #218807)

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 12:07:43 PDT 2026


================
@@ -27,6 +27,39 @@ struct E {
   constexpr E(){};
 } TestE;
 
+// Defined delegating constructor where delegated constructor is not defined
+// should not emit full debug info.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Delegating"{{.*}}flags: DIFlagFwdDecl
+struct Delegating {
+  Delegating() : Delegating(42) {}
+  Delegating(int);
+} TestDelegating;
+
+// Defined delegating constructor where delegated constructor is defined should
+// emit full debug info.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "DelegatingToDefined"{{.*}}DIFlagTypePassByValue
+struct DelegatingToDefined {
+  DelegatingToDefined() : DelegatingToDefined(42) {}
+  DelegatingToDefined(int) {}
+} TestDelegatingToDefined;
+
+// Defined out-of-line delegating constructor where delegated constructor is
+// defined should emit full debug info.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "DelegatingOutOfLine"{{.*}}DIFlagTypePassByValue
+struct DelegatingOutOfLine {
+  DelegatingOutOfLine();
+  DelegatingOutOfLine(int) {}
+};
+DelegatingOutOfLine d;
+DelegatingOutOfLine::DelegatingOutOfLine() : DelegatingOutOfLine(42) {}
----------------
dwblaikie wrote:

> A declared-but-not-defined delegating constructor looks just like a non-delegating constructor. You can't tell if a constructor is delegating until you see its definition.

Yep, that'd be my understanding/expectation.

> If you mean the constructor that is being delegated to (not sure how to word this in English haha), the `Delegating` test struct has an inline delegating ctor which delegates to a declared-but-not-defined ctor (no debug info). The `DelegatingToDefined` delegates to an inlined ctor.
> 
> I've added another test case `DelegatingToOutOfLine`, which is an inline delegating ctor delegating to an out-of-line ctor. It verifies that debug info should be emitted.

I'd have expected debug info to /not/ be emitted in this case, though? Oh, depending on whether theout-of-line ctor is defined or not. That's the case I'm curious about - a situation where the delegating ctor is emitted (probably doesn't matter if the ctor is inline or not - maybe it'd be easier/clearer if these test cases didn't use inline definitions?) but the ctor it is delegating to is not emitted (because it's not defined in this translation unit at all) - in which case I'd expect the delegated-to ctor to be a valid home for the type, so the TU where the delegating ctor is emitted would /not/ act as a home for the type.




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


More information about the cfe-commits mailing list