summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/consteval-memfn1.C
blob: 910e7a1ac1e4823e204ae495d6d36f4b264c1d99 (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
// PR c++/99895
// { dg-do compile { target c++20 } }

struct fixed_string {
  consteval int size(int n) const {
    if (n < 0) throw; // { dg-error "not a constant" }
    return n;
  }

  static consteval int size_static(int n) {
    if (n < 0) throw; // { dg-error "not a constant" }
    return n;
  }

  consteval void operator()() const { }
};

template<class>
void VerifyHash(fixed_string s) {
  s.size(0); // { dg-bogus "" }
  s.size(-1); // { dg-message "expansion of" }
  s.size_static(0); // { dg-bogus "" }
  s.size_static(-1); // { dg-message "expansion of" }
  fixed_string::size_static(0); // { dg-bogus "" }
  fixed_string::size_static(-1); // { dg-message "expansion of" }
  s(); // { dg-bogus "" }
}