Skip to content

Commit 8b89f6a

Browse files
committed
[Clang] Deleting an incomplete enum type is not an error
The changes introduced in #97733 accidentally prevented to delete an incomplete enum (the validity of which has been confirmed by CWG2925 Fixes #99278
1 parent 5b0f4f2 commit 8b89f6a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ Bug Fixes to C++ Support
766766
- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
767767
- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
768768
captures at the end of a full expression. (#GH115931)
769+
- Clang no longer rejects deleting a pointer of incomplete enumeration type. (#GH99278)
769770

770771
Bug Fixes to AST Handling
771772
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,7 +3748,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
37483748
// FIXME: This can result in errors if the definition was imported from a
37493749
// module but is hidden.
37503750
if (!RequireCompleteType(StartLoc, Pointee,
3751-
LangOpts.CPlusPlus26
3751+
Pointee->isStructureOrClassType() &&
3752+
LangOpts.CPlusPlus26
37523753
? diag::err_delete_incomplete
37533754
: diag::warn_delete_incomplete,
37543755
Ex.get())) {

clang/test/SemaCXX/new-delete.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,14 @@ namespace PR10504 {
540540
void f(A *x) { delete x; } // expected-warning {{delete called on 'PR10504::A' that is abstract but has non-virtual destructor}}
541541
}
542542

543+
#if __cplusplus >= 201103L
544+
enum GH99278_1 { // expected-note {{definition of 'GH99278_1' is not complete until the closing '}'}}
545+
zero = decltype(delete static_cast<GH99278_1*>(nullptr), 0){}
546+
// expected-warning@-1 {{deleting pointer to incomplete type}}
547+
// expected-warning@-2 {{expression with side effects has no effect in an unevaluated context}}
548+
};
549+
#endif
550+
543551
struct PlacementArg {};
544552
inline void *operator new[](size_t, const PlacementArg &) throw () {
545553
return 0;

0 commit comments

Comments
 (0)