Backport/20.x: [Clang] Fix an incorrect assumption on getTemplatedDecl() · llvm/llvm-project@1cfbb9f (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1059,6 +1059,7 @@ Bug Fixes to C++ Support
1059 1059 corresponding to a pack parameter (#GH124715)
1060 1060 - Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
1061 1061 - Fixed an integer overflow bug in computing template parameter depths when synthesizing CTAD guides. (#GH128691)
1062 +- Fixed an incorrect pointer access when checking access-control on concepts. (#GH131530)
1062 1063
1063 1064 Bug Fixes to AST Handling
1064 1065 ^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1518,8 +1518,8 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) {
1518 1518 } else if (FunctionDecl *FN = dyn_cast(D)) {
1519 1519 DC = FN;
1520 1520 } else if (TemplateDecl *TD = dyn_cast(D)) {
1521 -if (isa(TD->getTemplatedDecl()))
1522 - DC = cast(TD->getTemplatedDecl());
1521 +if (auto *D = dyn_cast_if_present(TD->getTemplatedDecl()))
1522 + DC = D;
1523 1523 } else if (auto *RD = dyn_cast(D)) {
1524 1524 DC = RD;
1525 1525 }
Original file line number Diff line number Diff line change
@@ -36,3 +36,15 @@ void function() {
36 36 // expected-note@#4 {{candidate template ignored: constraints not satisfied [with IteratorL = Object *, IteratorR = Object *]}}
37 37 // We don't know exactly the substituted type for `lhs == rhs`, thus a placeholder 'expr-type' is emitted.
38 38 // 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
47 +concept is_foo_concept = __is_same(foo::bar, T);
48 +// expected-error@-1 {{'bar' is a private member of 'GH131530::foo'}}
49 +
50 +}