aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-06-11 11:20:19 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-06-11 13:28:23 +0200
commit424188abe4956d51c852668d206dfc9919290fbf (patch)
tree52e3cfc7dcf269329d6eec4c97d1c8e9faa89723
parent2dc2290860355dd2bac3b655eea895fe30fde257 (diff)
downloadllvm-424188abe4956d51c852668d206dfc9919290fbf.zip
llvm-424188abe4956d51c852668d206dfc9919290fbf.tar.gz
llvm-424188abe4956d51c852668d206dfc9919290fbf.tar.bz2
[clang][Interp][test] Add test for void* diagnostics changes
-rw-r--r--clang/test/AST/Interp/cxx23.cpp16
-rw-r--r--clang/test/AST/Interp/cxx26.cpp10
2 files changed, 24 insertions, 2 deletions
diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp
index 1efd784..d0991f3 100644
--- a/clang/test/AST/Interp/cxx23.cpp
+++ b/clang/test/AST/Interp/cxx23.cpp
@@ -1,6 +1,6 @@
// UNSUPPORTED: target={{.*}}-zos{{.*}}
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all20 %s
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23,all %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref,ref20,all,all20 %s
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref,ref23,all %s
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all20 %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23,all %s -fexperimental-new-constant-interpreter
@@ -200,3 +200,15 @@ namespace UndefinedThreeWay {
static_assert(!(*test_a_threeway)(A(), A())); // all-error {{static assertion expression is not an integral constant expression}} \
// all-note {{undefined function 'operator<=>' cannot be used in a constant expression}}
}
+
+/// FIXME: The new interpreter is missing the "initializer of q is not a constant expression" diagnostics.a
+/// That's because the cast from void* to int* is considered fine, but diagnosed. So we don't consider
+/// q to be uninitialized.
+namespace VoidCast {
+ constexpr void* p = nullptr;
+ constexpr int* q = static_cast<int*>(p); // all-error {{must be initialized by a constant expression}} \
+ // all-note {{cast from 'void *' is not allowed in a constant expression}} \
+ // ref-note {{declared here}}
+ static_assert(q == nullptr); // ref-error {{not an integral constant expression}} \
+ // ref-note {{initializer of 'q' is not a constant expression}}
+}
diff --git a/clang/test/AST/Interp/cxx26.cpp b/clang/test/AST/Interp/cxx26.cpp
new file mode 100644
index 0000000..0b0e2b2
--- /dev/null
+++ b/clang/test/AST/Interp/cxx26.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter
+
+// both-no-diagnostics
+
+namespace VoidCast {
+ constexpr void* p = nullptr;
+ constexpr int* q = static_cast<int*>(p);
+ static_assert(q == nullptr);
+}