[clang] [Clang] fix bad codegen from constexpr structured bindings (PR #186594)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 19 10:08:51 PDT 2026


================
@@ -7357,11 +7357,12 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
           E->getStorageDuration() == SD_Thread) && "not a global temporary");
   const auto *VD = cast<VarDecl>(E->getExtendingDecl());
 
-  // If we're not materializing a subobject of the temporary, keep the
-  // cv-qualifiers from the type of the MaterializeTemporaryExpr.
-  QualType MaterializedType = Init->getType();
-  if (Init == E->getSubExpr())
-    MaterializedType = E->getType();
+  // Keep cv-qualifiers from the MaterializeTemporaryExpr on the storage type.
+  // The initializer expression may have had rvalue subobject adjustments
+  // stripped, which can drop top-level qualifiers that are still part of the
+  // materialized temporary's type.
+  QualType MaterializedType = getContext().getQualifiedType(
----------------
efriedma-quic wrote:

I think this is basically the right idea, but I'm not confident this is quite right.

In particular, I'm a little worried about the interaction with "mutable"; if a constant temporary has a mutable subobject, we can't put a "const" qualifier on it.

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


More information about the cfe-commits mailing list