[clang] 0baa7ba - [Clang][Sema] Only call PerformDependentDiagnostics for dependent contexts (#177452)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 13 06:26:41 PDT 2026


Author: Krystian Stasiowski
Date: 2026-03-13T09:26:36-04:00
New Revision: 0baa7bac708350fce440614be335103b968da2aa

URL: https://github.com/llvm/llvm-project/commit/0baa7bac708350fce440614be335103b968da2aa
DIFF: https://github.com/llvm/llvm-project/commit/0baa7bac708350fce440614be335103b968da2aa.diff

LOG: [Clang][Sema] Only call PerformDependentDiagnostics for dependent contexts (#177452)

Added: 
    clang/test/SemaTemplate/GH176155.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 658461b13fd40..031d7405e7f58 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 972981d7c11fb..cc24e03e77c07 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 0000000000000..12a9de2ae2d46
--- /dev/null
+++ b/clang/test/SemaTemplate/GH176155.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+template <int> struct bad {
+  template <class T, auto =
+                         [] { // #lambda
+                           // expected-note@#lambda {{while substituting into a lambda expression here}}
+                           // expected-note@#lambda 2{{capture 'i' by value}}
+                           // expected-note@#lambda 2{{capture 'i' by reference}}
+                           // expected-note@#lambda 2{{default capture by value}}
+                           // expected-note@#lambda 2{{default capture by reference}}
+                           for (int i = 0; i < 100; ++i) { // #i
+                             // expected-error at -1 {{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
+                             // expected-note@#i {{'i' declared here}}
+                             // expected-note@#lambda {{lambda expression begins here}}
+                             // expected-error at -4 {{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
+                             // expected-note@#i {{'i' declared here}}
+                             // expected-note@#lambda {{lambda expression begins here}}
+                             struct LoopHelper {
+                               static constexpr void process() {}
+                             };
+                           }
+                         }>
+  static void f(T) {} // expected-note {{in instantiation of default argument for 'f<int>' required here}}
+};
+
+int main() { bad<0>::f(0); } // expected-note {{while substituting deduced template arguments into function template 'f'}}


        


More information about the cfe-commits mailing list