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

This commit is contained in:
Krystian Stasiowski 2026-03-13 09:26:36 -04:00 committed by GitHub
parent 9d20e75c2d
commit 0baa7bac70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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);

View File

@ -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@-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@-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'}}