Skip to content

Commit 424188a

Browse files
committed
[clang][Interp][test] Add test for void* diagnostics changes
1 parent 2dc2290 commit 424188a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

clang/test/AST/Interp/cxx23.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// UNSUPPORTED: target={{.*}}-zos{{.*}}
2-
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all20 %s
3-
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23,all %s
2+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref,ref20,all,all20 %s
3+
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref,ref23,all %s
44
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all20 %s -fexperimental-new-constant-interpreter
55
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23,all %s -fexperimental-new-constant-interpreter
66

@@ -200,3 +200,15 @@ namespace UndefinedThreeWay {
200200
static_assert(!(*test_a_threeway)(A(), A())); // all-error {{static assertion expression is not an integral constant expression}} \
201201
// all-note {{undefined function 'operator<=>' cannot be used in a constant expression}}
202202
}
203+
204+
/// FIXME: The new interpreter is missing the "initializer of q is not a constant expression" diagnostics.a
205+
/// That's because the cast from void* to int* is considered fine, but diagnosed. So we don't consider
206+
/// q to be uninitialized.
207+
namespace VoidCast {
208+
constexpr void* p = nullptr;
209+
constexpr int* q = static_cast<int*>(p); // all-error {{must be initialized by a constant expression}} \
210+
// all-note {{cast from 'void *' is not allowed in a constant expression}} \
211+
// ref-note {{declared here}}
212+
static_assert(q == nullptr); // ref-error {{not an integral constant expression}} \
213+
// ref-note {{initializer of 'q' is not a constant expression}}
214+
}

clang/test/AST/Interp/cxx26.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=ref,both %s
2+
// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter
3+
4+
// both-no-diagnostics
5+
6+
namespace VoidCast {
7+
constexpr void* p = nullptr;
8+
constexpr int* q = static_cast<int*>(p);
9+
static_assert(q == nullptr);
10+
}

0 commit comments

Comments
 (0)