]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Make *_cast<*> parsing more robust to errors [PR108438]
authorSimon Martin <simon@nasilyan.com>
Fri, 7 Jun 2024 09:21:07 +0000 (11:21 +0200)
committerSimon Martin <simon@nasilyan.com>
Sat, 8 Jun 2024 11:08:12 +0000 (13:08 +0200)
commit2c9643c27ecddb7f597d34009d89e932b4aca58e
treee04897fed77b40e924c0a775483391e9d4300113
parentde05e44b2ad9638d04173393b1eae3c38b2c3864
c++: Make *_cast<*> parsing more robust to errors [PR108438]

We ICE upon the following when trying to emit a -Wlogical-not-parentheses
warning:

=== cut here ===
template <typename T> T foo (T arg, T& ref, T* ptr) {
  int a = 1;
  return static_cast<T!>(a);
}
=== cut here ===

This patch makes *_cast<*> parsing more robust by skipping to the closing '>'
upon error in the target type.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/108438

gcc/cp/ChangeLog:

* parser.cc (cp_parser_postfix_expression): Use
cp_parser_require_end_of_template_parameter_list to skip to the closing
'>' upon error parsing the target type of *_cast<*> expressions.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash75.C: New test.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/parse/crash75.C [new file with mode: 0644]