]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix wrong-code with overloaded comma and CPP_EMBED [PR123737]
authorJakub Jelinek <jakub@redhat.com>
Sat, 24 Jan 2026 09:38:17 +0000 (10:38 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 24 Jan 2026 09:38:17 +0000 (10:38 +0100)
commite2f626b37ef62fcab8667b2a67318c27a8f2a6ca
tree670a05b8c343ca5562a8c4593f1072266b45185e
parent34a47a8b14e2a74d35a65ccc2bd2a166106b9b96
c++: Fix wrong-code with overloaded comma and CPP_EMBED [PR123737]

In cp_parser_expression for comma operator I've used a short path
where instead of calling build_x_compound_expr #embed number times
it is called just 3 times, for the CPP_NUMBER added by the preprocessor
at the start, last byte from CPP_EMBED and then CPP_NUMBER added by
libcpp at the end, enough to make sure -Wunused-value reports something,
but not bothering users with millions of -Wunused-value warnings
and spending too much compile time on it when they use a very large #embed.

As the following testcases show, that is ok for C or for C++ if the
expression before it is known not to have OVERLOAD_TYPE_P (common case
is INTEGER_TYPE I guess), but doesn't work well in case one uses overloaded
comma operator.  In that case we just have to call build_x_compound_expr
the right number of times, even if it is a lot.

I think I don't need to test for !expression, because the preprocessor
should guarantee that CPP_EMBED is preceded by CPP_NUMBER CPP_COMMA
tokens.

2026-01-24  Jakub Jelinek  <jakub@redhat.com>

PR c++/123737
* parser.cc (cp_parser_expression): Don't handle CPP_EMBED just
as the last byte in it if expression has or might have overloaded
type.  In that case call build_x_compound_expr for each byte
in CPP_EMBED separately.

* g++.dg/cpp/embed-28.C: New test.
* g++.dg/parse/comma3.C: New test.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp/embed-28.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/comma3.C [new file with mode: 0644]