Skip to content

Commit d911085

Browse files
authored
[Clang] Fix an incorrect assumption on getTemplatedDecl() (#131559)
Since a68d20e, we've been calling HandleDelayedAccessCheck() for concept declarations when the declaration contains invalid member accesses. However, a concept declaration is TemplateDecl such that doesn't contain any TemplatedDecl. Fixes #131530
1 parent a10e1e0 commit d911085

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/lib/Sema/SemaAccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) {
15181518
} else if (FunctionDecl *FN = dyn_cast<FunctionDecl>(D)) {
15191519
DC = FN;
15201520
} else if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
1521-
if (isa<DeclContext>(TD->getTemplatedDecl()))
1522-
DC = cast<DeclContext>(TD->getTemplatedDecl());
1521+
if (auto *D = dyn_cast_if_present<DeclContext>(TD->getTemplatedDecl()))
1522+
DC = D;
15231523
} else if (auto *RD = dyn_cast<RequiresExprBodyDecl>(D)) {
15241524
DC = RD;
15251525
}

clang/test/SemaCXX/concept-crash-on-diagnostic.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ void function() {
3636
// expected-note@#4 {{candidate template ignored: constraints not satisfied [with IteratorL = Object *, IteratorR = Object *]}}
3737
// We don't know exactly the substituted type for `lhs == rhs`, thus a placeholder 'expr-type' is emitted.
3838
// expected-note@#3 {{because 'convertible_to<expr-type, bool>' would be invalid}}
39+
40+
namespace GH131530 {
41+
42+
class foo {
43+
struct bar {}; // expected-note {{implicitly declared private}}
44+
};
45+
46+
template <typename T>
47+
concept is_foo_concept = __is_same(foo::bar, T);
48+
// expected-error@-1 {{'bar' is a private member of 'GH131530::foo'}}
49+
50+
}

0 commit comments

Comments
 (0)