https://github.com/Serosh-commits created https://github.com/llvm/llvm-project/pull/190484
fix by guarding `CppNamespaceLookup` with an `isFileContext()` check instead of asserting fixes #189344 >From f51ccca155c2f6ee9259c84d0dbe2cf3df1075bc Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Sun, 5 Apr 2026 01:40:44 +0530 Subject: [PATCH] Fix name lookup crash Fixes crash in CppLookupName. --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaLookup.cpp | 5 +---- clang/test/SemaCXX/gh189344.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaCXX/gh189344.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 899a4ee0dee0e..a7cda9b03715a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -549,6 +549,7 @@ Bug Fixes to Attribute Support Bug Fixes to C++ Support ^^^^^^^^^^^^^^^^^^^^^^^^ +- Fixed a name lookup crash when parsing invalid template parameters. (#GH189344) - Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665) - Suppress ``-Wdeprecated-declarations`` in implicitly generated functions. (#GH147293) - Fix a crash when deleting a pointer to an incomplete array (#GH150359). diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index b9fac5a4a1153..a5c33d0738e2d 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1528,10 +1528,7 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { // If we have a context, and it's not a context stashed in the // template parameter scope for an out-of-line definition, also // look into that context. - if (!(Found && S->isTemplateParamScope())) { - assert(Ctx->isFileContext() && - "We should have been looking only at file context here already."); - + if (Ctx->isFileContext() && !(Found && S->isTemplateParamScope())) { // Look into context considering using-directives. if (CppNamespaceLookup(*this, R, Context, Ctx, UDirs)) Found = true; diff --git a/clang/test/SemaCXX/gh189344.cpp b/clang/test/SemaCXX/gh189344.cpp new file mode 100644 index 0000000000000..19d1244fbc15d --- /dev/null +++ b/clang/test/SemaCXX/gh189344.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template <union { } alignas ( union a { c ) ( a :: ) ( :: (b +// expected-error@-1 {{cannot be defined in a type specifier}} +// expected-error@-1 {{'a' cannot be defined in a type specifier}} +// expected-error@-1 {{expected unqualified-id}} +// expected-error@-1 {{expected unqualified-id}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
