aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/consteval21.C
blob: 06ec705c75bc477783bc0c8d9d4f8d2c67aeeaae (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
35
// PR c++/102753
// { dg-do compile { target c++20 } }

struct S {
  constexpr S () : s (0) {}
  consteval int foo () { return 1; }
  virtual consteval int bar () { return 2; }
  int s;
};

consteval int foo () { return 42; }

consteval int
bar (int (*fn) () = &foo)
{
  return fn ();
}

consteval int
baz (int (S::*fn) () = &S::foo)
{
  S s;
  return (s.*fn) ();
}

consteval int
qux (int (S::*fn) () = &S::bar)
{
  S s;
  return (s.*fn) ();
}

static_assert (bar () == 42);
static_assert (baz () == 1);
static_assert (qux () == 2);