[clang] [Clang] Ensure child classes export inherited constructors from base classes (PR #182706)
Chinmay Deshpande via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 07:05:52 PST 2026
================
@@ -6604,13 +6617,42 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) {
if (MD->isDeleted())
continue;
+ // Don't export inherited constructors whose parameters prevent ABI-
+ // compatible forwarding thunk. When canEmitDelegateCallArgs (in
+ // CodeGen) returns false, Clang inlines the constructor body instead
+ // of emitting a forwarding thunk, producing code that is not ABI-
+ // compatible with MSVC. Suppress the export so the user gets a linker
+ // error rather than a silent runtime mismatch.
+ if (ClassExported) {
+ if (auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
+ if (CD->getInheritedConstructor()) {
+ if (CD->isVariadic())
+ continue;
+ if (Context.getTargetInfo()
+ .getCXXABI()
+ .areArgsDestroyedLeftToRightInCallee()) {
+ bool HasCalleeCleanupParam = false;
+ for (const auto *P : CD->parameters())
+ if (P->needsDestruction(Context))
+ HasCalleeCleanupParam = true;
+ if (HasCalleeCleanupParam)
+ continue;
+ }
+ }
+ }
+ }
----------------
chinmaydd wrote:
Gentle ping @efriedma-quic @Fznamznon
https://github.com/llvm/llvm-project/pull/182706
More information about the cfe-commits
mailing list