Debian Codegraph @

clang/test/SemaCXX/type-aware-new-invalid-type-identity.cpp

raw
1 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26 -DINVALID_TYPE_IDENTITY_VERSION=0
2 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26 -DINVALID_TYPE_IDENTITY_VERSION=1
3 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26 -DINVALID_TYPE_IDENTITY_VERSION=2
4 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26 -DINVALID_TYPE_IDENTITY_VERSION=3
5 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26 -DINVALID_TYPE_IDENTITY_VERSION=4
6 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26
7
8 namespace std {
9 #if !defined(INVALID_TYPE_IDENTITY_VERSION)
10 // expected-no-diagnostics
11 template <class T> struct type_identity {
12 };
13 #define TYPE_IDENTITY(T) std::type_identity<T>
14 #elif INVALID_TYPE_IDENTITY_VERSION==0
15 struct type_identity {};
16 // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
17 #define TYPE_IDENTITY(T) std::type_identity
18 #elif INVALID_TYPE_IDENTITY_VERSION==1
19 template <class A, class B> struct type_identity {};
20 // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
21 #define TYPE_IDENTITY(T) std::type_identity<T, int>
22 #elif INVALID_TYPE_IDENTITY_VERSION==2
23 enum type_identity {};
24 // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
25 #define TYPE_IDENTITY(T) std::type_identity
26 #elif INVALID_TYPE_IDENTITY_VERSION==3
27 template <class T> using type_identity = int;
28 #define TYPE_IDENTITY(T) std::type_identity<T>
29 #elif INVALID_TYPE_IDENTITY_VERSION==4
30 template <class T> struct inner {};
31 template <class T> using type_identity = inner<T>;
32 #define TYPE_IDENTITY(T) std::type_identity<T>
33 #endif
34 using size_t = __SIZE_TYPE__;
35 enum class align_val_t : long {};
36 }
37
38 template <class T> void *operator new(TYPE_IDENTITY(T), std::size_t, std::align_val_t); // #operator_new
39 template <class T> void operator delete(TYPE_IDENTITY(T), void*, std::size_t, std::align_val_t); // #operator_delete
40
41 // These error messages aren't great, but they fall out of the way we model
42 // alias types. Getting them in this way requires extremely unlikely code to be
43 // used, so this is not terrible.
44
45 #if INVALID_TYPE_IDENTITY_VERSION==3
46 // expected-error@#operator_new {{'operator new' takes type size_t ('unsigned long') as 1st parameter}}
47 // expected-error@#operator_delete {{1st parameter of 'operator delete' must have type 'void *'}}
48 #elif INVALID_TYPE_IDENTITY_VERSION==4
49 // expected-error@#operator_new {{'operator new' cannot take a dependent type as its 1st parameter; use size_t ('unsigned long') instead}}
50 // expected-error@#operator_delete {{'operator delete' cannot take a dependent type as its 1st parameter; use 'void *' instead}}
51 #endif
52
53 using size_t = __SIZE_TYPE__;
54 struct TestType {};
55
56 void f() {
57 TestType *t = new TestType;
58 delete t;
59 }