diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index f79d9a758e7af..6813786df3fc4 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -1518,8 +1518,8 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) { } else if (FunctionDecl *FN = dyn_cast(D)) { DC = FN; } else if (TemplateDecl *TD = dyn_cast(D)) { - if (isa(TD->getTemplatedDecl())) - DC = cast(TD->getTemplatedDecl()); + if (auto *D = dyn_cast_if_present(TD->getTemplatedDecl())) + DC = D; } else if (auto *RD = dyn_cast(D)) { DC = RD; } diff --git a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp index 71e55c8290ee4..c38f8888075de 100644 --- a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp +++ b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp @@ -36,3 +36,15 @@ void function() { // expected-note@#4 {{candidate template ignored: constraints not satisfied [with IteratorL = Object *, IteratorR = Object *]}} // We don't know exactly the substituted type for `lhs == rhs`, thus a placeholder 'expr-type' is emitted. // expected-note@#3 {{because 'convertible_to' would be invalid}} + +namespace GH131530 { + +class foo { + struct bar {}; // expected-note {{implicitly declared private}} +}; + +template +concept is_foo_concept = __is_same(foo::bar, T); +// expected-error@-1 {{'bar' is a private member of 'GH131530::foo'}} + +}