Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval-memfn2.C

raw
1 // PR c++/99895
2 // { dg-do compile { target c++20 } }
3
4 static constexpr unsigned hash(const char* s, unsigned length)
5 {
6 s=s;
7 return length;
8 }
9 template<unsigned N>
10 struct fixed_string
11 {
12 constexpr fixed_string(const char (&s)[N])
13 {
14 for (int i = 0; i < N; i++)
15 str[i] = s[i];
16 }
17 consteval const char* data() const { return str; }
18 consteval unsigned size() const { return N-1; }
19 char str[N];
20 };
21 template<unsigned expected_hash, fixed_string... s>
22 static consteval void VerifyHash()
23 {
24 (
25 [](auto){static_assert(hash(s.data(), s.size()) == expected_hash);}(s)
26 ,...);
27 // The compiler mistakenly translates s.data() into s.data(&s)
28 // and then complains that the call is not valid, because
29 // the function expects 0 parameters and 1 "was provided".
30 }
31 void foo()
32 {
33 VerifyHash<5, "khaki", "plums">();
34 }