[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 18:37:40 PDT 2026
https://github.com/w007878 created https://github.com/llvm/llvm-project/pull/203736
fixes #203701
>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] 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}}
+}
More information about the cfe-commits
mailing list