aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/consteval-memfn2.C
blob: 71748f46b13330b2b7b2cd0dadf75b474c96a09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// PR c++/99895
// { dg-do compile { target c++20 } }

static constexpr unsigned hash(const char* s, unsigned length)
{
    s=s;
    return length;
}
template<unsigned N>
struct fixed_string
{
    constexpr fixed_string(const char (&s)[N])
    {
        for (int i = 0; i < N; i++)
            str[i] = s[i];
    }
    consteval const char* data() const { return str; }
    consteval unsigned size() const { return N-1; }
    char str[N];
};
template<unsigned expected_hash, fixed_string... s>
static consteval void VerifyHash()
{
    (
      [](auto){static_assert(hash(s.data(), s.size()) == expected_hash);}(s)
    ,...);
    // The compiler mistakenly translates s.data() into s.data(&s)
    // and then complains that the call is not valid, because
    // the function expects 0 parameters and 1 "was provided".
}
void foo()
{
    VerifyHash<5, "khaki", "plums">();
}