c++: Keep DECL_SAVED_TREE of cdtor instantiations in modules [PR104040]
A template instantiation still needs to have its DECL_SAVED_TREE so that its definition is emitted into the CMI. This way it can be emitted in the object file of any importers that use it, in case it doesn't end up getting emitted in this TU. This is true even for maybe-in-charge functions, because we don't currently stream the clones directly but instead regenerate them from this function. PR c++/104040 gcc/cp/ChangeLog: * semantics.cc (expand_or_defer_fn_1): Keep DECL_SAVED_TREE for all vague linkage cdtors with modules. gcc/testsuite/ChangeLog: * g++.dg/modules/pr104040_a.C: New test. * g++.dg/modules/pr104040_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
parent
ea665f9026
commit
0774240b4d
3 changed files with 28 additions and 2 deletions
|
@ -5029,9 +5029,13 @@ expand_or_defer_fn_1 (tree fn)
|
|||
/* We don't want to process FN again, so pretend we've written
|
||||
it out, even though we haven't. */
|
||||
TREE_ASM_WRITTEN (fn) = 1;
|
||||
/* If this is a constexpr function, keep DECL_SAVED_TREE. */
|
||||
/* If this is a constexpr function we still need the body to be
|
||||
able to evaluate it. Similarly, with modules we only stream
|
||||
the maybe-in-charge cdtor and regenerate the clones from it on
|
||||
demand, so we also need to keep the body. Otherwise we don't
|
||||
need it anymore. */
|
||||
if (!DECL_DECLARED_CONSTEXPR_P (fn)
|
||||
&& !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
|
||||
&& !(modules_p () && vague_linkage_p (fn)))
|
||||
DECL_SAVED_TREE (fn) = NULL_TREE;
|
||||
return false;
|
||||
}
|
||||
|
|
14
gcc/testsuite/g++.dg/modules/pr104040_a.C
Normal file
14
gcc/testsuite/g++.dg/modules/pr104040_a.C
Normal file
|
@ -0,0 +1,14 @@
|
|||
// PR c++/104040
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
// { dg-module-cmi test }
|
||||
|
||||
export module test;
|
||||
|
||||
export template <typename T>
|
||||
struct test {
|
||||
~test() {}
|
||||
};
|
||||
|
||||
test<bool> use() {
|
||||
return {};
|
||||
}
|
8
gcc/testsuite/g++.dg/modules/pr104040_b.C
Normal file
8
gcc/testsuite/g++.dg/modules/pr104040_b.C
Normal file
|
@ -0,0 +1,8 @@
|
|||
// PR c++/104040
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
|
||||
import test;
|
||||
|
||||
int main() {
|
||||
test<bool> t{};
|
||||
}
|
Loading…
Add table
Reference in a new issue