From df9769e14b79048331c33deeda1a93acc9a4a73e Mon Sep 17 00:00:00 2001 From: "Oleksandr T." Date: Fri, 1 Nov 2024 07:13:33 +0200 Subject: [PATCH] [Clang] prevent setting default lexical access specifier for missing primary declarations (#112424) This PR resolves a crash triggered by a forward reference to an enum type in a function parameter list. The fix includes setting `Invalid` when `TagUseKind` is `Declaration` to ensure correct error handling. Fixes #112208 --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 2 ++ clang/test/SemaCXX/enum.cpp | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4e542ee91a8b..b99dd441db25 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure in range calculations for conditional throw expressions. (#GH111854) - Clang now correctly ignores previous partial specializations of member templates explicitly specialized for an implicitly instantiated class template specialization. (#GH51051) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index c56883a80c1c..0cdace25aa79 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17955,6 +17955,8 @@ CreateNewDecl: << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration) + Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da88..44042d8bf5cf 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ + // expected-error {{unexpected ';' before ')'}} +}; +}