[clang] 424188a - [clang][Interp][test] Add test for void* diagnostics changes
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 04:28:42 PDT 2024
Author: Timm Bäder
Date: 2024-06-11T13:28:23+02:00
New Revision: 424188abe4956d51c852668d206dfc9919290fbf
URL: https://github.com/llvm/llvm-project/commit/424188abe4956d51c852668d206dfc9919290fbf
DIFF: https://github.com/llvm/llvm-project/commit/424188abe4956d51c852668d206dfc9919290fbf.diff
LOG: [clang][Interp][test] Add test for void* diagnostics changes
Added:
clang/test/AST/Interp/cxx26.cpp
Modified:
clang/test/AST/Interp/cxx23.cpp
Removed:
################################################################################
diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp
index 1efd784abbbe8..d0991f3ffdff5 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 0000000000000..0b0e2b21e8201
--- /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);
+}
More information about the cfe-commits
mailing list