Skip to content

Commit 9a3f2f2

Browse files
committed
Improve language feature extension warnings update release notes
1 parent ae0729d commit 9a3f2f2

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ C++2c Feature Support
8181

8282
- Implemented `P0963R3 Structured binding declaration as a condition <https://wg21.link/P0963R3>`_.
8383

84+
- Implemented `P2719Rx Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_.
85+
8486
C++23 Feature Support
8587
^^^^^^^^^^^^^^^^^^^^^
8688

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9844,8 +9844,11 @@ def err_type_aware_destroying_operator_delete : Error<
98449844
"type aware destroying delete is not permitted in C++26">;
98459845
def err_unsupported_type_aware_allocator : Error<
98469846
"type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'">;
9847-
def warn_cxx26_type_aware_allocator : Warning<
9848-
"use or declaration of type aware allocators are incompatible with C++ standards before C++26">,
9847+
9848+
def ext_cxx26_type_aware_allocators : ExtWarn<
9849+
"type aware allocators are a C++2c extension">, InGroup<CXX26>;
9850+
def warn_cxx26_type_aware_allocators : Warning<
9851+
"type aware allocators are incompatible with C++ standards before C++2c">,
98499852
DefaultIgnore, InGroup<CXXPre26Compat>;
98509853
def err_no_type_aware_cleanup_operator_delete : Error<
98519854
"type aware %0 requires there to be a corresponding cleanup %1 in %2">;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16444,9 +16444,12 @@ static inline bool CheckOperatorNewDeleteTypes(
1644416444
if (!SemaRef.getLangOpts().TypeAwareAllocators)
1644516445
return SemaRef.Diag(FnDecl->getLocation(),
1644616446
diag::err_unsupported_type_aware_allocator);
16447-
if (!SemaRef.getLangOpts().CPlusPlus26)
16448-
SemaRef.Diag(FnDecl->getLocation(),
16449-
diag::warn_cxx26_type_aware_allocator);
16447+
if (!FnDecl->isTemplateInstantiation()) {
16448+
unsigned DiagID = SemaRef.getLangOpts().CPlusPlus26
16449+
? diag::warn_cxx26_type_aware_allocators
16450+
: diag::ext_cxx26_type_aware_allocators;
16451+
SemaRef.Diag(FnDecl->getLocation(), DiagID);
16452+
}
1645016453

1645116454
if (OperatorKind == AllocationOperatorKind::New) {
1645216455
SizeParameterIndex = 1;

clang/test/SemaCXX/type-aware-new-delete-basic-in-class-declarations.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fcxx-type-aware-allocators
2-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26
3-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -DNO_TAA -std=c++23 -fno-cxx-type-aware-allocators
4-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -DNO_TAA -std=c++26 -fno-cxx-type-aware-allocators
1+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify=expected,precxx26 %s -std=c++23 -fcxx-type-aware-allocators
2+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26
3+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify=expected,precxx26 %s -DNO_TAA -std=c++23 -fno-cxx-type-aware-allocators
4+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -DNO_TAA -std=c++26 -fno-cxx-type-aware-allocators
55

66
namespace std {
77
template <class T> struct type_identity {};
@@ -18,6 +18,9 @@ struct S {
1818
#if defined(NO_TAA)
1919
//expected-error@#1 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
2020
//expected-error@#2 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
21+
#else
22+
// precxx26-warning@#1 {{type aware allocators are a C++2c extension}}
23+
// precxx26-warning@#2 {{type aware allocators are a C++2c extension}}
2124
#endif
2225
void operator delete(S *, std::destroying_delete_t);
2326
};
@@ -28,6 +31,9 @@ template <typename T> struct S2 {
2831
#if defined(NO_TAA)
2932
//expected-error@#3 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
3033
//expected-error@#4 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
34+
#else
35+
// precxx26-warning@#3 {{type aware allocators are a C++2c extension}}
36+
// precxx26-warning@#4 {{type aware allocators are a C++2c extension}}
3137
#endif
3238
void operator delete(S2 *, std::destroying_delete_t);
3339
};
@@ -38,6 +44,9 @@ struct S3 {
3844
#if defined(NO_TAA)
3945
//expected-error@#5 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
4046
//expected-error@#6 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
47+
#else
48+
// precxx26-warning@#5 {{type aware allocators are a C++2c extension}}
49+
// precxx26-warning@#6 {{type aware allocators are a C++2c extension}}
4150
#endif
4251
void operator delete(S3 *, std::destroying_delete_t);
4352
};
@@ -51,6 +60,8 @@ struct S4 {
5160
//expected-error@#8 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
5261
//expected-error@#9 {{type aware destroying delete is not permitted in C++26}}
5362
#else
63+
// precxx26-warning@#7 {{type aware allocators are a C++2c extension}}
64+
// precxx26-warning@#8 {{type aware allocators are a C++2c extension}}
5465
// expected-error@#9 {{type aware destroying delete is not permitted in C++26}}
5566
#endif
5667
};
@@ -65,6 +76,7 @@ struct S5 {
6576
// expected-error@#10 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
6677
#else
6778
// expected-error@#10 {{type aware 'operator delete' cannot take a dependent type as its second parameter}}
79+
// precxx26-warning@#10 {{type aware allocators are a C++2c extension}}
6880
#endif
6981
};
7082

@@ -74,12 +86,14 @@ struct S6 {
7486
// expected-error@#11 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
7587
#else
7688
// expected-error@#11 {{type aware 'operator new' cannot take a dependent type as its second parameter}}
89+
// precxx26-warning@#11 {{type aware allocators are a C++2c extension}}
7790
#endif
7891
template <typename T> void operator delete(std::type_identity<S6>, T, size_t, std::align_val_t); // #12
7992
#if defined(NO_TAA)
8093
// expected-error@#12 {{type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'}}
8194
#else
8295
// expected-error@#12 {{type aware 'operator delete' cannot take a dependent type as its second parameter}}
96+
// precxx26-warning@#12 {{type aware allocators are a C++2c extension}}
8397
#endif
8498
};
8599

@@ -88,8 +102,10 @@ template <typename U>
88102
struct S7 {
89103
template <typename T> void *operator new(std::type_identity<T>, U, std::align_val_t); // #13
90104
// expected-error@#13 {{type aware 'operator new' cannot take a dependent type as its second parameter;}}
105+
// precxx26-warning@#13 {{type aware allocators are a C++2c extension}}
91106
template <typename T> void operator delete(std::type_identity<T>, U, size_t, std::align_val_t); // #14
92107
// expected-error@#14 {{type aware 'operator delete' cannot take a dependent type as its second parameter;}}
108+
// precxx26-warning@#14 {{type aware allocators are a C++2c extension}}
93109
template <typename T> void operator delete(std::type_identity<T>, S7 *, std::destroying_delete_t, U, std::align_val_t); // #15
94110
// expected-error@#15 {{type aware destroying delete is not permitted in C++26}}
95111
void operator delete(S7 *, std::destroying_delete_t, U); // #16
@@ -104,8 +120,10 @@ void f() {
104120
struct S8 {
105121
template <typename T, typename U> void *operator new(std::type_identity<T>, U, std::align_val_t); // #17
106122
// expected-error@#17 {{type aware 'operator new' cannot take a dependent type as its second parameter;}}
123+
// precxx26-warning@#17 {{type aware allocators are a C++2c extension}}
107124
template <typename T, typename U> void operator delete(std::type_identity<T>, U, size_t, std::align_val_t); // #18
108125
// expected-error@#18 {{type aware 'operator delete' cannot take a dependent type as its second parameter;}}
126+
// precxx26-warning@#18 {{type aware allocators are a C++2c extension}}
109127
template <typename T, typename U> void operator delete(std::type_identity<T>, S8 *, std::destroying_delete_t, U, std::align_val_t); // #19
110128
// expected-error@#19 {{type aware destroying delete is not permitted in C++26}}
111129
};
@@ -116,16 +134,24 @@ typedef std::type_identity<double> TypedefAlias;
116134
using UsingAlias = std::type_identity<float>;
117135
struct S9 {
118136
void *operator new(Alias<size_t>, std::align_val_t);
119-
template <typename T> void *operator new(Alias<std::type_identity<T>>, Alias<size_t>, std::align_val_t);
137+
template <typename T> void *operator new(Alias<std::type_identity<T>>, Alias<size_t>, std::align_val_t); // #20
138+
// precxx26-warning@#20 {{type aware allocators are a C++2c extension}}
120139
void *operator new(Alias<std::type_identity<int>>, size_t, std::align_val_t);
121-
template <typename T> void operator delete(Alias<std::type_identity<T>>, void *, size_t, std::align_val_t);
140+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
141+
template <typename T> void operator delete(Alias<std::type_identity<T>>, void *, size_t, std::align_val_t); // #21
142+
// precxx26-warning@#21{{type aware allocators are a C++2c extension}}
122143
void operator delete(Alias<std::type_identity<int>>, void *, size_t, std::align_val_t);
144+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
123145
};
124146
struct S10 {
125-
template <typename T> void *operator new(TypeIdentityAlias<T>, size_t, std::align_val_t);
147+
template <typename T> void *operator new(TypeIdentityAlias<T>, size_t, std::align_val_t); // #22
148+
// precxx26-warning@#22 {{type aware allocators are a C++2c extension}}
126149
void *operator new(TypeIdentityAlias<int>, size_t, std::align_val_t);
127-
template <typename T> void operator delete(TypeIdentityAlias<T>, void *, size_t, std::align_val_t);
150+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
151+
template <typename T> void operator delete(TypeIdentityAlias<T>, void *, size_t, std::align_val_t); // #23
152+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
128153
void operator delete(TypeIdentityAlias<int>, void *, size_t, std::align_val_t);
154+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
129155
};
130156

131157
void test() {
@@ -137,20 +163,30 @@ void test() {
137163

138164
struct S11 {
139165
template <typename T> void *operator new(TypedefAlias, size_t, std::align_val_t);
166+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
140167
void *operator new(TypedefAlias, size_t, std::align_val_t);
168+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
141169
template <typename T> void operator delete(TypedefAlias, void *, size_t, std::align_val_t);
170+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
142171
void operator delete(TypedefAlias, void *, size_t, std::align_val_t);
172+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
143173
};
144174
struct S12 {
145175
template <typename T> void *operator new(UsingAlias, size_t, std::align_val_t);
176+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
146177
void *operator new(UsingAlias, size_t, std::align_val_t);
178+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
147179
template <typename T> void operator delete(UsingAlias, void *, size_t, std::align_val_t);
180+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
148181
void operator delete(UsingAlias, void *, size_t, std::align_val_t);
182+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
149183
};
150184

151185
struct S13 {
152186
void *operator new(std::type_identity<S13>, size_t, std::align_val_t);
187+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
153188
void operator delete(std::type_identity<S13>, void*, size_t, std::align_val_t);
189+
// precxx26-warning@-1 {{type aware allocators are a C++2c extension}}
154190
};
155191

156192
#endif

clang/test/SemaCXX/type-aware-new-delete-basic-resolution.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fcxx-type-aware-allocators -fexceptions -fsized-deallocation -faligned-allocation
2-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fcxx-type-aware-allocators -fexceptions -fno-sized-deallocation -faligned-allocation
3-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fcxx-type-aware-allocators -fexceptions -fsized-deallocation -fno-aligned-allocation
4-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fcxx-type-aware-allocators -fexceptions -fno-sized-deallocation -fno-aligned-allocation
1+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26 -fexceptions -fsized-deallocation -faligned-allocation
2+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26 -fexceptions -fno-sized-deallocation -faligned-allocation
3+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26 -fexceptions -fsized-deallocation -fno-aligned-allocation
4+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++26 -fexceptions -fno-sized-deallocation -fno-aligned-allocation
55

66
namespace std {
77
template <class T> struct type_identity {};

0 commit comments

Comments
 (0)