[clang] [CLANG-CL] Remove the 'static' specifier for _FUNCTION_ in MSVC mode. (PR #128184)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 10:35:35 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Zahira Ammarguellat (zahiraam)
<details>
<summary>Changes</summary>
The macro `FUNCTION` is returning the `static` specifier for static templated functions. It's not the case for MSVC.
See https://godbolt.org/z/KnhWhqs47
Clang-cl is returning:
`__FUNCTION__ static inner::C<class A>::f`
`__FUNCTION__ static inner::C<class A>::f`
for the reproducer.
---
Full diff: https://github.com/llvm/llvm-project/pull/128184.diff
2 Files Affected:
- (modified) clang/lib/AST/Expr.cpp (+4-2)
- (modified) clang/test/SemaCXX/source_location.cpp (+31)
``````````diff
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b747aa8df807d..a019dd2818e59 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -747,8 +747,10 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual)
Out << "virtual ";
- if (MD->isStatic())
- Out << "static ";
+ if (MD->isStatic()) {
+ if (!ForceElaboratedPrinting)
+ Out << "static ";
+ }
}
class PrettyCallbacks final : public PrintingCallbacks {
diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp
index 069a9004927a9..a9fca2a17c939 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -524,6 +524,37 @@ TestClass<test_func::C> t2;
TestStruct<test_func::S> t3;
TestEnum<test_func::E> t4;
+class A { int b;};
+namespace inner {
+ template <class Ty>
+ class C {
+ public:
+ template <class T>
+ static void f(int i) {
+ (void)i;
+#ifdef MS
+ static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f"));
+#else
+ static_assert(is_equal(__FUNCTION__, "f"));
+#endif
+ }
+ template <class T>
+ static void f(double f) {
+ (void)f;
+#ifdef MS
+ static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f"));
+#else
+ static_assert(is_equal(__FUNCTION__, "f"));
+#endif
+ }
+ };
+}
+
+ void foo() {
+ test_func::inner::C<test_func::A>::f<char>(1);
+ test_func::inner::C<test_func::A>::f<void>(1.0);
+}
+
} // namespace test_func
``````````
</details>
https://github.com/llvm/llvm-project/pull/128184
More information about the cfe-commits
mailing list