diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-05-22 10:31:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-22 10:31:39 +0200 |
commit | 7cfeedf64addf6d20bdf47a669936ba6e46593d8 (patch) | |
tree | 9e56e330c6dc45e6b5809fb98c4f2fdb5d3d0962 /clang/test/AST/ByteCode | |
parent | 466720960bd34532ecc342207ef4b81c98cae3c5 (diff) | |
download | llvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.zip llvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.tar.gz llvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.tar.bz2 |
[clang][bytecode] Change diagnostics for self-initialization (#141006)
Change the diagnostics when reading from the variable we're currently
initializing do be the same as the one the current interpreter emits.
Diffstat (limited to 'clang/test/AST/ByteCode')
-rw-r--r-- | clang/test/AST/ByteCode/cxx11.cpp | 10 | ||||
-rw-r--r-- | clang/test/AST/ByteCode/cxx17.cpp | 9 |
2 files changed, 17 insertions, 2 deletions
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 3682211..44725f1 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -23,6 +23,16 @@ int array2[recurse2]; // both-warning {{variable length arrays in C++}} \ // expected-error {{variable length array declaration not allowed at file scope}} \ // ref-warning {{variable length array folded to constant array as an extension}} +constexpr int b = b; // both-error {{must be initialized by a constant expression}} \ + // both-note {{read of object outside its lifetime is not allowed in a constant expression}} + + +[[clang::require_constant_initialization]] int c = c; // both-error {{variable does not have a constant initializer}} \ + // both-note {{attribute here}} \ + // both-note {{read of non-const variable}} \ + // both-note {{declared here}} + + struct S { int m; }; diff --git a/clang/test/AST/ByteCode/cxx17.cpp b/clang/test/AST/ByteCode/cxx17.cpp index 9453906..08a40e0 100644 --- a/clang/test/AST/ByteCode/cxx17.cpp +++ b/clang/test/AST/ByteCode/cxx17.cpp @@ -1,5 +1,10 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++17 -verify=expected,both %s -// RUN: %clang_cc1 -std=c++17 -verify=ref,both %s +// RUN: %clang_cc1 -std=c++17 -verify=expected,both %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++17 -verify=ref,both %s + +[[clang::require_constant_initialization]] int cc = cc; // both-error {{variable does not have a constant initializer}} \ + // both-note {{attribute here}} \ + // both-note {{ead of object outside its lifetime}} + struct F { int a; int b;}; constexpr F getF() { |