Modules streaming requires DECL_CONTEXT to be set for anything streamed.
This patch ensures that 'create_temporary_var' does set a DECL_CONTEXT
for these variables (such as the backing storage for initializer_lists)
even if not inside a function declaration.
PR c++/114005
gcc/cp/ChangeLog:
* init.cc (create_temporary_var): Use current_scope instead of
current_function_decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/pr114005_a.C: New test.
* g++.dg/modules/pr114005_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
TREE_USED (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
- DECL_CONTEXT (decl) = current_function_decl;
+ DECL_CONTEXT (decl) = current_scope ();
return decl;
}
--- /dev/null
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi M }
+
+module;
+#include <initializer_list>
+
+export module M;
+export constexpr std::initializer_list<int> foo{ 1, 2, 3 };
--- /dev/null
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+
+int main() {
+ return foo.size();
+}