From 0baa7bac708350fce440614be335103b968da2aa Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 13 Mar 2026 09:26:36 -0400 Subject: [PATCH] [Clang][Sema] Only call PerformDependentDiagnostics for dependent contexts (#177452) --- clang/docs/ReleaseNotes.rst | 1 + .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 3 ++- clang/test/SemaTemplate/GH176155.cpp | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaTemplate/GH176155.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 658461b13fd4..031d7405e7f5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -326,6 +326,7 @@ Bug Fixes in This Version - Fixed a crash when parsing ``#pragma clang attribute`` arguments for attributes that forbid arguments. (#GH182122) - Fixed a bug with multiple-include optimization (MIOpt) state not being preserved in some cases during lexing, which could suppress header-guard mismatch diagnostics and interfere with include-guard optimization. (#GH180155) - Fixed a crash when normalizing constraints involving concept template parameters whose index coincided with non-concept template parameters in the same parameter mapping. +- Fixed a crash caused by accessing dependent diagnostics of a non-dependent context. Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 972981d7c11f..cc24e03e77c0 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5969,7 +5969,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, checkReferenceToTULocalFromOtherTU(Function, PointOfInstantiation); - PerformDependentDiagnostics(PatternDecl, TemplateArgs); + if (PatternDecl->isDependentContext()) + PerformDependentDiagnostics(PatternDecl, TemplateArgs); if (auto *Listener = getASTMutationListener()) Listener->FunctionDefinitionInstantiated(Function); diff --git a/clang/test/SemaTemplate/GH176155.cpp b/clang/test/SemaTemplate/GH176155.cpp new file mode 100644 index 000000000000..12a9de2ae2d4 --- /dev/null +++ b/clang/test/SemaTemplate/GH176155.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +template struct bad { + template + static void f(T) {} // expected-note {{in instantiation of default argument for 'f' required here}} +}; + +int main() { bad<0>::f(0); } // expected-note {{while substituting deduced template arguments into function template 'f'}}