Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / AST / Interp / cxx23.cpp
blobe284a66626fb331f69fc84298fe9326c78c8e8db
1 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20 %s
2 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23 %s
3 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20 %s -fexperimental-new-constant-interpreter
4 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23 %s -fexperimental-new-constant-interpreter
7 // expected23-no-diagnostics
10 /// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics.
12 constexpr int f(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
13 // ref23-error {{constexpr function never produces a constant expression}}
14 static const int m = n; // ref20-note {{control flows through the definition of a static variable}} \
15 // ref20-warning {{is a C++23 extension}} \
16 // ref23-note {{control flows through the definition of a static variable}} \
17 // expected20-warning {{is a C++23 extension}}
19 return m;
21 constexpr int g(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
22 // ref23-error {{constexpr function never produces a constant expression}}
23 thread_local const int m = n; // ref20-note {{control flows through the definition of a thread_local variable}} \
24 // ref20-warning {{is a C++23 extension}} \
25 // ref23-note {{control flows through the definition of a thread_local variable}} \
26 // expected20-warning {{is a C++23 extension}}
27 return m;
30 constexpr int c_thread_local(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
31 // ref23-error {{constexpr function never produces a constant expression}}
32 static _Thread_local int m = 0; // ref20-note {{control flows through the definition of a thread_local variable}} \
33 // ref20-warning {{is a C++23 extension}} \
34 // ref23-note {{control flows through the definition of a thread_local variable}} \
35 // expected20-warning {{is a C++23 extension}}
36 return m;
40 constexpr int gnu_thread_local(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
41 // ref23-error {{constexpr function never produces a constant expression}}
42 static __thread int m = 0; // ref20-note {{control flows through the definition of a thread_local variable}} \
43 // ref20-warning {{is a C++23 extension}} \
44 // ref23-note {{control flows through the definition of a thread_local variable}} \
45 // expected20-warning {{is a C++23 extension}}
46 return m;
49 constexpr int h(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
50 // ref23-error {{constexpr function never produces a constant expression}}
51 static const int m = n; // ref20-note {{control flows through the definition of a static variable}} \
52 // ref20-warning {{is a C++23 extension}} \
53 // ref23-note {{control flows through the definition of a static variable}} \
54 // expected20-warning {{is a C++23 extension}}
55 return &m - &m;
58 constexpr int i(int n) { // ref20-error {{constexpr function never produces a constant expression}} \
59 // ref23-error {{constexpr function never produces a constant expression}}
60 thread_local const int m = n; // ref20-note {{control flows through the definition of a thread_local variable}} \
61 // ref20-warning {{is a C++23 extension}} \
62 // ref23-note {{control flows through the definition of a thread_local variable}} \
63 // expected20-warning {{is a C++23 extension}}
64 return &m - &m;
67 constexpr int j(int n) {
68 if (!n)
69 return 0;
70 static const int m = n; // ref20-warning {{is a C++23 extension}} \
71 // expected20-warning {{is a C++23 extension}}
72 return m;
74 constexpr int j0 = j(0);
76 constexpr int k(int n) {
77 if (!n)
78 return 0;
79 thread_local const int m = n; // ref20-warning {{is a C++23 extension}} \
80 // expected20-warning {{is a C++23 extension}}
82 return m;
84 constexpr int k0 = k(0);