https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/184210
>From bef7ff3e56b90452e5d1e86b7f5d4559bf97725e Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Thu, 5 Mar 2026 02:24:01 +0530 Subject: [PATCH 1/2] fix explicit incomplete enum --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaOverload.cpp | 3 +++ clang/test/SemaCXX/gh183887.cpp | 8 ++++++++ 3 files changed, 12 insertions(+) create mode 100644 clang/test/SemaCXX/gh183887.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 18ce0f919daa9..82b80e2b287c5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -334,6 +334,7 @@ Bug Fixes to C++ Support - Fixed a bug where captured variables in non-mutable lambdas were incorrectly treated as mutable when used inside decltype in the return type. (#GH180460) - Fixed a crash when evaluating uninitialized GCC vector/ext_vector_type vectors in ``constexpr``. (#GH180044) +- Fixed a crash when `explicit(bool)` is used with an incomplete enumeration. (#GH183887) - Fixed a crash on ``typeid`` of incomplete local types during template instantiation. (#GH63242), (#GH176397) - Fix initialization of GRO when GRO-return type mismatches, as part of CWG2563. (#GH98744) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index e5c4c59e9ffbb..429202b799910 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6464,6 +6464,9 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, if (checkPlaceholderForOverload(S, From)) return ExprError(); + if (From->containsErrors()) + return S.ImpCastExprToType(From, T, CK_NoOp, From->getValueKind()); + // C++1z [expr.const]p3: // A converted constant expression of type T is an expression, // implicitly converted to type T, where the converted diff --git a/clang/test/SemaCXX/gh183887.cpp b/clang/test/SemaCXX/gh183887.cpp new file mode 100644 index 0000000000000..d89b2d5068ea0 --- /dev/null +++ b/clang/test/SemaCXX/gh183887.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +namespace GH183887 { +enum E1 explicit(E1()); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ + // expected-error {{invalid use of incomplete type 'E1'}} \ + // expected-error {{'explicit' can only appear on non-static member functions}} \ + // expected-note {{forward declaration of 'GH183887::E1'}} +} >From 28040e6f45e3abfd7e2ee2a428b5cd89b12aeaea Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Tue, 10 Mar 2026 23:51:22 +0530 Subject: [PATCH 2/2] use RecoveryExpr and add comments --- clang/lib/Sema/SemaOverload.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 429202b799910..81085fa423e06 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6464,8 +6464,13 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, if (checkPlaceholderForOverload(S, From)) return ExprError(); - if (From->containsErrors()) - return S.ImpCastExprToType(From, T, CK_NoOp, From->getValueKind()); + if (From->containsErrors()) { + // The expression already has errors, so the correct cast kind can't be + // determined. Use RecoveryExpr to keep the expected type T and mark the + // result as invalid, preventing further cascading errors. + return S.CreateRecoveryExpr(From->getBeginLoc(), From->getEndLoc(), {From}, + T); + } // C++1z [expr.const]p3: // A converted constant expression of type T is an expression, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
