]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix up ICEs on constexpr inline asm strings in templates [PR118277]
authorJakub Jelinek <jakub@redhat.com>
Fri, 10 Jan 2025 09:32:36 +0000 (10:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 10 Jan 2025 09:32:36 +0000 (10:32 +0100)
commit38a13ea4117b96e467f78b3f86d737ecbe326935
tree282426171edc144a459cadc402dab8dee18be034
parent933f0c20d4ce1dba85e85d9d117cfd9f5376a945
c++: Fix up ICEs on constexpr inline asm strings in templates [PR118277]

The following patch fixes ICEs when the new inline asm syntax
to use C++26 static_assert-like constant expressions in place
of string literals is used in templates.
As finish_asm_stmt doesn't do any checking for
processing_template_decl, this patch also just defers handling
those strings in templates rather than say trying fold_non_dependent_expr
and if the result is non-dependent and usable, try to extract.

The patch also reverts changes to cp_parser_asm_specification_opt
which allowed something like
void foo () asm ((std::string_view ("bar")));
but it would be really hard to support
template <int N>
void baz () asm ((std::string_view ("qux")));
(especially with dependent constant expression).

And the patch adds extensive test coverage for the various errors.

2025-01-10  Jakub Jelinek  <jakub@redhat.com>

PR c++/118277
* cp-tree.h (finish_asm_string_expression): Declare.
* semantics.cc (finish_asm_string_expression): New function.
(finish_asm_stmt): Use it.
* parser.cc (cp_parser_asm_string_expression): Likewise.
Wrap string into PAREN_EXPR in the ("") case.
(cp_parser_asm_definition): Don't ICE if finish_asm_stmt
returns error_mark_node.
(cp_parser_asm_specification_opt): Revert 2024-06-24 changes.
* pt.cc (tsubst_stmt): Don't ICE if finish_asm_stmt returns
error_mark_node.

* g++.dg/cpp1z/constexpr-asm-4.C: New test.
* g++.dg/cpp1z/constexpr-asm-5.C: New test.
gcc/cp/cp-tree.h
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp1z/constexpr-asm-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C [new file with mode: 0644]