aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit4.C
blob: bdc97a9bc79213b0776ffa8262ed0d81c69a605f (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// { dg-do compile }
// { dg-options "-std=c++2b" }

int qux ();

constexpr int
foo (int x)
{
  switch (x)
    {
      static int v = qux ();
    case 12:
      return 1;
    }
  return 0;
}

constexpr int
bar (int x)
{
  switch (x)
    {
      thread_local int v = qux ();
    case 12:
      return 1;
    }
  return 0;
}

constexpr int
baz (int x)
{
  switch (x)
    {
      static const int v = qux ();	// { dg-message "'v' was not initialized with a constant expression" }
    case 12:
      return v;	// { dg-error "the value of 'v' is not usable in a constant expression" }
    }
  return 0;
}

constexpr int
corge (int x)
{
  switch (x)
    {
      const thread_local int v = qux ();	// { dg-message "'v' was not initialized with a constant expression" }
    case 12:
      return v; // { dg-error "the value of 'v' is not usable in a constant expression" }
    }
  return 0;
}

constexpr int a = foo (12);
constexpr int b = bar (12);
constexpr int c = baz (12);
constexpr int d = corge (12);