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>
This commit is contained in:
parent
b7b387e120
commit
2823b4d96d
3 changed files with 16 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
8
gcc/testsuite/g++.dg/modules/pr114005_a.C
Normal file
8
gcc/testsuite/g++.dg/modules/pr114005_a.C
Normal file
|
@ -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 };
|
7
gcc/testsuite/g++.dg/modules/pr114005_b.C
Normal file
7
gcc/testsuite/g++.dg/modules/pr114005_b.C
Normal file
|
@ -0,0 +1,7 @@
|
|||
// { dg-additional-options "-fmodules-ts" }
|
||||
|
||||
import M;
|
||||
|
||||
int main() {
|
||||
return foo.size();
|
||||
}
|
Loading…
Add table
Reference in a new issue