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  <jakub@redhat.com>

	* g++.dg/reflect/lwg4556.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
Jakub Jelinek
2026-04-03 10:26:31 +02:00
committed by Jakub Jelinek
parent 0229b5b3da
commit 581a9a289d

View File

@@ -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 }
}