aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-11-18 14:35:22 -0500
committerJason Merrill <jason@redhat.com>2023-12-21 19:19:50 -0500
commitd26f589e61a178e898d8b247042b487287ffe121 (patch)
treeb1c2cc9b6d39fafac1ad34663048988b1e833dc6 /gcc/cp
parent2fa122cae50cd87c1262c4ec18a783ee9bbbdaaa (diff)
downloadgcc-d26f589e61a178e898d8b247042b487287ffe121.zip
gcc-d26f589e61a178e898d8b247042b487287ffe121.tar.gz
gcc-d26f589e61a178e898d8b247042b487287ffe121.tar.bz2
c++: sizeof... mangling with alias template [PR95298]
We were getting sizeof... mangling wrong when the argument after substitution was a pack expansion that is not a simple T..., such as list<T>... in variadic-mangle4.C or (A+1)... in variadic-mangle5.C. In the former case we ICEd; in the latter case we wrongly mangled it as sZ <expression>. PR c++/95298 gcc/cp/ChangeLog: * mangle.cc (write_expression): Handle v18 sizeof... bug. * pt.cc (tsubst_pack_expansion): Keep TREE_VEC for sizeof... (tsubst_expr): Don't strip TREE_VEC here. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/variadic-mangle2.C: Add non-member. * g++.dg/cpp0x/variadic-mangle4.C: New test. * g++.dg/cpp0x/variadic-mangle5.C: New test. * g++.dg/cpp0x/variadic-mangle5a.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/mangle.cc14
-rw-r--r--gcc/cp/pt.cc12
2 files changed, 23 insertions, 3 deletions
diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index 365d470..36c5ac5 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -3444,6 +3444,7 @@ write_expression (tree expr)
if (PACK_EXPANSION_P (op))
{
+ sizeof_pack:
if (abi_check (11))
{
/* sZ rather than szDp. */
@@ -3464,6 +3465,19 @@ write_expression (tree expr)
int length = TREE_VEC_LENGTH (args);
if (abi_check (10))
{
+ /* Before v19 we wrongly mangled all single pack expansions with
+ sZ, but now only for expressions, as types ICEd (95298). */
+ if (length == 1)
+ {
+ tree arg = TREE_VEC_ELT (args, 0);
+ if (TREE_CODE (arg) == EXPR_PACK_EXPANSION
+ && !abi_check (19))
+ {
+ op = arg;
+ goto sizeof_pack;
+ }
+ }
+
/* sP <template-arg>* E # sizeof...(T), size of a captured
template parameter pack from an alias template */
write_string ("sP");
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2817657..5278ef6 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13572,7 +13572,15 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
/* If the argument pack is a single pack expansion, pull it out. */
if (TREE_VEC_LENGTH (args) == 1
&& pack_expansion_args_count (args))
- return TREE_VEC_ELT (args, 0);
+ {
+ tree arg = TREE_VEC_ELT (args, 0);
+ if (PACK_EXPANSION_SIZEOF_P (t)
+ && !TEMPLATE_PARM_P (PACK_EXPANSION_PATTERN (arg)))
+ /* Except if this isn't a simple sizeof...(T) which gets sZ
+ mangling, keep the TREE_VEC to get sP mangling. */;
+ else
+ return TREE_VEC_ELT (args, 0);
+ }
/* Types need no adjustment, nor does sizeof..., and if we still have
some pack expansion args we won't do anything yet. */
@@ -20261,8 +20269,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
if (PACK_EXPANSION_P (expanded))
/* OK. */;
- else if (TREE_VEC_LENGTH (expanded) == 1)
- expanded = TREE_VEC_ELT (expanded, 0);
else
expanded = make_argument_pack (expanded);