[clang] [WIP][clang] use getDeclName in static assert failed boolean condition printer (PR #203736)
Fan Mo via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 13 19:43:07 PDT 2026
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/2] 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/2] 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'}}
}
More information about the cfe-commits
mailing list