Debian Codegraph @

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

raw
1 // PR c++/99895
2 // { dg-do compile { target c++20 } }
3 // Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'.
4
5 struct fixed_string {
6 consteval int size(int n) const {
7 if (n < 0) throw; // { dg-error "not a constant" }
8 return n;
9 }
10
11 static consteval int size_static(int n) {
12 if (n < 0) throw; // { dg-error "not a constant" }
13 return n;
14 }
15
16 consteval void operator()() const { }
17 };
18
19 template<class>
20 void VerifyHash(fixed_string s) {
21 s.size(0); // { dg-bogus "" }
22 s.size(-1); // { dg-message "expansion of" }
23 // { dg-error "call to consteval function" "" { target *-*-* } .-1 }
24 s.size_static(0); // { dg-bogus "" }
25 s.size_static(-1); // { dg-message "expansion of" }
26 // { dg-error "call to consteval function" "" { target *-*-* } .-1 }
27 fixed_string::size_static(0); // { dg-bogus "" }
28 fixed_string::size_static(-1); // { dg-message "expansion of" }
29 // { dg-error "call to consteval function" "" { target *-*-* } .-1 }
30 s(); // { dg-bogus "" }
31 }
32
33 void
34 do_test ()
35 {
36 fixed_string f;
37 VerifyHash<int>(f);
38 }