Skip to content

Commit 6d759f8

Browse files
authored
[Clang] Deleting an incomplete enum type is not an error (#119077)
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 411df3b commit 6d759f8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

clang/docs/ReleaseNotes.rst

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

803804
Bug Fixes to AST Handling
804805
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3747,7 +3747,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
37473747
} else if (!Pointee->isDependentType()) {
37483748
// FIXME: This can result in errors if the definition was imported from a
37493749
// module but is hidden.
3750-
if (!RequireCompleteType(StartLoc, Pointee,
3750+
if (Pointee->isEnumeralType() ||
3751+
!RequireCompleteType(StartLoc, Pointee,
37513752
LangOpts.CPlusPlus26
37523753
? diag::err_delete_incomplete
37533754
: diag::warn_delete_incomplete,

clang/test/SemaCXX/new-delete.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,22 @@ 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 {
545+
zero = decltype(delete static_cast<GH99278_1*>(nullptr), 0){}
546+
// expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}}
547+
};
548+
template <typename = void>
549+
struct GH99278_2 {
550+
union b {};
551+
struct c {
552+
c() { delete d; }
553+
b *d;
554+
} f;
555+
};
556+
GH99278_2<void> e;
557+
#endif
558+
543559
struct PlacementArg {};
544560
inline void *operator new[](size_t, const PlacementArg &) throw () {
545561
return 0;

0 commit comments

Comments
 (0)