]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Ensure type of partial spec VAR_DECL is consistent with its template...
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 23 Jun 2025 12:24:22 +0000 (22:24 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 28 Jun 2025 14:52:30 +0000 (00:52 +1000)
commit98fd493db6216cff11142c9dc477a3ff8e4269fa
tree9388dc4d80349a273bc79b63d7bfc4df25d89c85
parent13390e1b65f499ba33b7b5ff76bd9936e81b74e4
c++/modules: Ensure type of partial spec VAR_DECL is consistent with its template [PR120644]

We were erroring because the TEMPLATE_DECL of the existing partial
specialisation has an undeduced return type, but the imported
declaration did not.

The root cause is similar to what was fixed in r13-2744-g4fac53d6522189,
where modules streaming code assumes that a TEMPLATE_DECL and its
DECL_TEMPLATE_RESULT will always have the same TREE_TYPE.  That commit
fixed the issue by ensuring that when the type of a variable is deduced
the TEMPLATE_DECL is updated as well, but missed handling partial
specialisations.  This patch ensures that the same adjustment is made
there as well.

PR c++/120644

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Also propagate type to partial
templates.
* module.cc (trees_out::decl_value): Add assertion that the
TREE_TYPE of a streamed template decl matches its inner.
(trees_in::is_matching_decl): Clarify function return type
deduction should only occur for non-TEMPLATE_DECL.
* pt.cc (template_for_substitution): Handle partial specs.

gcc/testsuite/ChangeLog:

* g++.dg/modules/auto-7.h: New test.
* g++.dg/modules/auto-7_a.H: New test.
* g++.dg/modules/auto-7_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
gcc/cp/decl.cc
gcc/cp/module.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/auto-7.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/auto-7_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/auto-7_b.C [new file with mode: 0644]