File: type-aware-new-invalid-type-identity.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (59 lines) | stat: -rw-r--r-- 3,197 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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
// 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
// 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
// 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
// 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
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -Wno-ext-cxx-type-aware-allocators -std=c++26

namespace std {
#if !defined(INVALID_TYPE_IDENTITY_VERSION)
  // expected-no-diagnostics
  template <class T> struct type_identity {
  };
  #define TYPE_IDENTITY(T) std::type_identity<T>
#elif INVALID_TYPE_IDENTITY_VERSION==0
  struct type_identity {};
  // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
  #define TYPE_IDENTITY(T) std::type_identity
#elif INVALID_TYPE_IDENTITY_VERSION==1
  template <class A, class B> struct type_identity {};
  // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
  #define TYPE_IDENTITY(T) std::type_identity<T, int>
#elif INVALID_TYPE_IDENTITY_VERSION==2
  enum type_identity {};
  // expected-error@-1 {{std::type_identity must be a class template with a single type parameter}}
  #define TYPE_IDENTITY(T) std::type_identity
#elif INVALID_TYPE_IDENTITY_VERSION==3
  template <class T> using type_identity = int;
  #define TYPE_IDENTITY(T) std::type_identity<T>
#elif INVALID_TYPE_IDENTITY_VERSION==4
  template <class T> struct inner {};
  template <class T> using type_identity = inner<T>;
  #define TYPE_IDENTITY(T) std::type_identity<T>
#endif
  using size_t = __SIZE_TYPE__;
  enum class align_val_t : long {};
}

template <class T> void *operator new(TYPE_IDENTITY(T), std::size_t, std::align_val_t); // #operator_new
template <class T> void operator delete(TYPE_IDENTITY(T), void*, std::size_t, std::align_val_t); // #operator_delete

// These error messages aren't great, but they fall out of the way we model
// alias types. Getting them in this way requires extremely unlikely code to be
// used, so this is not terrible.

#if INVALID_TYPE_IDENTITY_VERSION==3
// expected-error@#operator_new {{'operator new' takes type size_t ('unsigned long') as 1st parameter}}
// expected-error@#operator_delete {{1st parameter of 'operator delete' must have type 'void *'}}
#elif INVALID_TYPE_IDENTITY_VERSION==4
// expected-error@#operator_new {{'operator new' cannot take a dependent type as its 1st parameter; use size_t ('unsigned long') instead}}
// expected-error@#operator_delete {{'operator delete' cannot take a dependent type as its 1st parameter; use 'void *' instead}}
#endif

using size_t = __SIZE_TYPE__;
struct TestType {};

void f() {
  TestType *t = new TestType;
  delete t;
}