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

Takashi Idobe via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 19 19:23:45 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(
----------------
Takashiidobe wrote:

Great find, I never knew this changed in C++11. I added the change and added some tests that exercise some extra edge cases including mutable cases. 

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


More information about the cfe-commits mailing list