https://gcc.gnu.org/g:581a9a289da068e05f7b41e80469a08ace4cf806
commit r16-8440-g581a9a289da068e05f7b41e80469a08ace4cf806 Author: Jakub Jelinek <[email protected]> Date: Fri Apr 3 10:26:31 2026 +0200 testsuite: Add testcase for LWG4556 - Unclear properties of reflection strings The issue clarifies what the *string_view points to is not valid for template arguments with pointer type, the following testcase verifies that we already reject it. 2026-04-03 Jakub Jelinek <[email protected]> * g++.dg/reflect/lwg4556.C: New test. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/testsuite/g++.dg/reflect/lwg4556.C | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gcc/testsuite/g++.dg/reflect/lwg4556.C b/gcc/testsuite/g++.dg/reflect/lwg4556.C new file mode 100644 index 000000000000..96918d379a4f --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/lwg4556.C @@ -0,0 +1,40 @@ +// LWG4556 - Unclear properties of reflection strings +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +#include <meta> + +template <const char *P> +void foo () {} + +template <const char8_t *P> +void bar () {} + +void +baz () +{ + foo <symbol_of (std::meta::op_plus_equals).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"\\\+=\\\"\\\[0\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8symbol_of (std::meta::op_pipe).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"\\\|\\\"\\\[0\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } + foo <symbol_of (std::meta::op_plus_equals).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"\\\+=\\\"\\\[1\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8symbol_of (std::meta::op_pipe).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"\\\|\\\"\\\[1\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } + foo <identifier_of (^^baz).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"baz\\\"\\\[0\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8identifier_of (^^baz).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"baz\\\"\\\[0\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } + foo <identifier_of (^^baz).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"baz\\\"\\\[1\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8identifier_of (^^baz).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"baz\\\"\\\[1\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } + foo <display_string_of (^^baz).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"void baz\\\(\\\)\\\"\\\[0\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8display_string_of (^^baz).data ()> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"void baz\\\(\\\)\\\"\\\[0\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } + foo <display_string_of (^^baz).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"void baz\\\(\\\)\\\"\\\[1\\\]' is not a valid template argument of type 'const char\\\*'" "" { target *-*-* } .-1 } + bar <u8display_string_of (^^baz).data () + 1> (); // { dg-error "no matching function for call to" } + // { dg-error "'\\\&\\\"void baz\\\(\\\)\\\"\\\[1\\\]' is not a valid template argument of type 'const char8_t\\\*'" "" { target *-*-* } .-1 } +}
