https://github.com/w007878 updated https://github.com/llvm/llvm-project/pull/203736
>From c5bf40cb6076c5a20bad7eb7997844236b360545 Mon Sep 17 00:00:00 2001
From: Fan Mo <w007878 at hotmail.com>
Date: Sat, 13 Jun 2026 20:33:20 -0500
Subject: [PATCH 1/3] fix: use getDeclName in static assert failed boolean
condition printer
---
clang/lib/Sema/SemaTemplate.cpp | 2 +-
clang/test/SemaCXX/static-assert.cpp | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 8c94a1ad39208..41664f36dd6a3 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3647,7 +3647,7 @@ class FailedBooleanConditionPrinterHelper : public PrinterHelper {
DR->getQualifier().print(OS, Policy, true);
// Then print the decl itself.
const ValueDecl *VD = DR->getDecl();
- OS << VD->getName();
+ OS << VD->getDeclName();
if (const auto *IV = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
// This is a template variable, print the expanded template arguments.
printTemplateArgumentList(
diff --git a/clang/test/SemaCXX/static-assert.cpp b/clang/test/SemaCXX/static-assert.cpp
index 354016db36432..f9c6378ecc396 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -364,3 +364,17 @@ namespace Diagnostics {
static_assert(1 << 3 != 8, ""); // expected-error {{failed}} \
// expected-note {{evaluates to '8 != 8'}}
}
+
+namespace GH203701 {
+ struct S {
+ constexpr S(auto) {}
+ constexpr operator int() const { return 0; }
+ constexpr static f() const { return 0; }
+ };
+
+ constexpr auto a = [](this S) { return 1; };
+
+ static_assert((&decltype(a)::operator())(1) == 42); // expected-error {{static assertion failed}}
+ static_assert((&S::operator int) == nullptr, ""); // expected-error {{static assertion failed}}
+ static_assert((S::f() == 1)); // expected-error {{static assertion failed}}
+}
>From 66e68710b4a2e4e220d45a54f18a891a52abe595 Mon Sep 17 00:00:00 2001
From: Fan Mo <w007878 at hotmail.com>
Date: Sat, 13 Jun 2026 21:42:16 -0500
Subject: [PATCH 2/3] fix test
---
clang/test/SemaCXX/static-assert.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/clang/test/SemaCXX/static-assert.cpp b/clang/test/SemaCXX/static-assert.cpp
index f9c6378ecc396..21a11ee7a5c45 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -369,12 +369,10 @@ namespace GH203701 {
struct S {
constexpr S(auto) {}
constexpr operator int() const { return 0; }
- constexpr static f() const { return 0; }
};
constexpr auto a = [](this S) { return 1; };
- static_assert((&decltype(a)::operator())(1) == 42); // expected-error {{static assertion failed}}
- static_assert((&S::operator int) == nullptr, ""); // expected-error {{static assertion failed}}
- static_assert((S::f() == 1)); // expected-error {{static assertion failed}}
+ static_assert((&decltype(a)::operator())(1) == 42, ""); // expected-error-re {{static assertion failed due to requirement '(&const GH203701::(lambda at {.*})::operator())(1) == 42'}}
+ static_assert((&S::operator int) == nullptr, ""); // expected-error {{static assertion failed due to requirement '(&GH203701::S::operator int) == nullptr'}}
}
>From 3088167d0348e6d13496edbac829eda93138beba Mon Sep 17 00:00:00 2001
From: Fan Mo <w007878 at hotmail.com>
Date: Sat, 13 Jun 2026 23:13:42 -0500
Subject: [PATCH 3/3] move test to c++17
---
clang/test/SemaCXX/static-assert-cxx17.cpp | 12 ++++++++++++
clang/test/SemaCXX/static-assert.cpp | 12 ------------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/clang/test/SemaCXX/static-assert-cxx17.cpp b/clang/test/SemaCXX/static-assert-cxx17.cpp
index 41a7b025d0eb7..e3038f8cec130 100644
--- a/clang/test/SemaCXX/static-assert-cxx17.cpp
+++ b/clang/test/SemaCXX/static-assert-cxx17.cpp
@@ -104,3 +104,15 @@ void foo6() {
}
template void foo6<ExampleTypes>();
// expected-note at -1{{in instantiation of function template specialization 'foo6<ExampleTypes>' requested here}}
+
+namespace GH203701 {
+ struct S {
+ constexpr S(auto) {}
+ constexpr operator int() const { return 0; }
+ };
+
+ constexpr auto a = [](this S) { return 1; };
+
+ static_assert((&decltype(a)::operator())(1) == 42, ""); // expected-error-re at -1 {{static assertion failed due to requirement '\(&const GH203701::\(lambda at {{.*}}\)::operator\(\)\)\(1\) == 42'}}
+ static_assert((&S::operator int) == nullptr, ""); // expected-error {{static assertion failed due to requirement '(&GH203701::S::operator int) == nullptr'}}
+}
diff --git a/clang/test/SemaCXX/static-assert.cpp b/clang/test/SemaCXX/static-assert.cpp
index 21a11ee7a5c45..354016db36432 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -364,15 +364,3 @@ namespace Diagnostics {
static_assert(1 << 3 != 8, ""); // expected-error {{failed}} \
// expected-note {{evaluates to '8 != 8'}}
}
-
-namespace GH203701 {
- struct S {
- constexpr S(auto) {}
- constexpr operator int() const { return 0; }
- };
-
- constexpr auto a = [](this S) { return 1; };
-
- static_assert((&decltype(a)::operator())(1) == 42, ""); // expected-error-re {{static assertion failed due to requirement '(&const GH203701::(lambda at {.*})::operator())(1) == 42'}}
- static_assert((&S::operator int) == nullptr, ""); // expected-error {{static assertion failed due to requirement '(&GH203701::S::operator int) == nullptr'}}
-}