|
| 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 |
| 5 | + |
| 6 | + |
| 7 | +// expected23-no-diagnostics |
| 8 | + |
| 9 | + |
| 10 | +/// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics. |
| 11 | + |
| 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}} |
| 18 | + |
| 19 | + return m; |
| 20 | +} |
| 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; |
| 28 | +} |
| 29 | + |
| 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; |
| 37 | +} |
| 38 | + |
| 39 | + |
| 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; |
| 47 | +} |
| 48 | + |
| 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; |
| 56 | +} |
| 57 | + |
| 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; |
| 65 | +} |
| 66 | + |
| 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; |
| 73 | +} |
| 74 | +constexpr int j0 = j(0); |
| 75 | + |
| 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}} |
| 81 | + |
| 82 | + return m; |
| 83 | +} |
| 84 | +constexpr int k0 = k(0); |
0 commit comments