Skip to content

Commit 1cfbb9f

Browse files
committed
Backport/20.x: [Clang] Fix an incorrect assumption on getTemplatedDecl()
This backports d911085 because it fixes a regression introduced in 19 and we don't want it to persist in 20
1 parent 0fcfeac commit 1cfbb9f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ Bug Fixes to C++ Support
10591059
corresponding to a pack parameter (#GH124715)
10601060
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
10611061
- 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)
10621063

10631064
Bug Fixes to AST Handling
10641065
^^^^^^^^^^^^^^^^^^^^^^^^^

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)