public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9266] c++: Ensure DECL_CONTEXT is set for temporary vars [PR114005]
@ 2024-03-01 22:05 Nathaniel Shead
0 siblings, 0 replies; only message in thread
From: Nathaniel Shead @ 2024-03-01 22:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2823b4d96d9ec4ad4e67e5e8edaa1b060a467491
commit r14-9266-g2823b4d96d9ec4ad4e67e5e8edaa1b060a467491
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date: Thu Feb 29 22:49:13 2024 +1100
c++: Ensure DECL_CONTEXT is set for temporary vars [PR114005]
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>
Diff:
---
gcc/cp/init.cc | 2 +-
gcc/testsuite/g++.dg/modules/pr114005_a.C | 8 ++++++++
gcc/testsuite/g++.dg/modules/pr114005_b.C | 7 +++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 1a341f7e606..d2586fad86b 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4258,7 +4258,7 @@ create_temporary_var (tree type)
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;
}
diff --git a/gcc/testsuite/g++.dg/modules/pr114005_a.C b/gcc/testsuite/g++.dg/modules/pr114005_a.C
new file mode 100644
index 00000000000..404683484ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114005_a.C
@@ -0,0 +1,8 @@
+// { 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 };
diff --git a/gcc/testsuite/g++.dg/modules/pr114005_b.C b/gcc/testsuite/g++.dg/modules/pr114005_b.C
new file mode 100644
index 00000000000..88317ce11f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114005_b.C
@@ -0,0 +1,7 @@
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+
+int main() {
+ return foo.size();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-01 22:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01 22:05 [gcc r14-9266] c++: Ensure DECL_CONTEXT is set for temporary vars [PR114005] Nathaniel Shead
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).