https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/131559

>From a3d01049bca20b9d44a07499b3204756edc8d0e1 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7...@gmail.com>
Date: Mon, 17 Mar 2025 12:41:42 +0800
Subject: [PATCH 1/2] [Clang] Fix an incorrect assumption on getTemplatedDecl()

Since a68d20e98, 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.
---
 clang/lib/Sema/SemaAccess.cpp                      |  4 ++--
 clang/test/SemaCXX/concept-crash-on-diagnostic.cpp | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

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<FunctionDecl>(D)) {
     DC = FN;
   } else if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
-    if (isa<DeclContext>(TD->getTemplatedDecl()))
-      DC = cast<DeclContext>(TD->getTemplatedDecl());
+    if (auto *D = dyn_cast_if_present<DeclContext>(TD->getTemplatedDecl()))
+      DC = D;
   } else if (auto *RD = dyn_cast<RequiresExprBodyDecl>(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..bd7b11a32e174 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<expr-type, bool>' would be 
invalid}}
+
+namespace GH131530 {
+
+class foo {
+  struct bar {}; // expected-note {{implicitly declared private}}
+};
+
+template <typename T>
+concept is_foo_concept = __is_same(foo::bar, T);
+// expected-error@-1 {{'bar' is a private member of 'foo'}}
+
+}

>From d620cf503d49df3dc1075084e2665f6386a8913b Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7...@gmail.com>
Date: Mon, 17 Mar 2025 12:55:47 +0800
Subject: [PATCH 2/2] Fix expected-error

---
 clang/test/SemaCXX/concept-crash-on-diagnostic.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp 
b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
index bd7b11a32e174..c38f8888075de 100644
--- a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
+++ b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
@@ -45,6 +45,6 @@ class foo {
 
 template <typename T>
 concept is_foo_concept = __is_same(foo::bar, T);
-// expected-error@-1 {{'bar' is a private member of 'foo'}}
+// expected-error@-1 {{'bar' is a private member of 'GH131530::foo'}}
 
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to