[CLANG-CL] Remove the 'static' specifier for _FUNCTION_ in MSVC mode. (#128184)

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.
This commit is contained in:
Zahira Ammarguellat 2025-03-06 04:51:45 -08:00 committed by GitHub
parent 59e0704a52
commit 7358973df1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 1 deletions

View File

@ -251,6 +251,8 @@ Bug Fixes in This Version
- Non-local variable and non-variable declarations in the first clause of a ``for`` loop in C are no longer incorrectly
considered an error in C23 mode and are allowed as an extension in earlier language modes.
- Remove the ``static`` specifier for the value of ``_FUNCTION_`` for static functions, in MSVC compatibility mode.
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -747,7 +747,7 @@ 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())
if (MD->isStatic() && !ForceElaboratedPrinting)
Out << "static ";
}

View File

@ -524,6 +524,57 @@ 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 constexpr void cf(int i) {
(void)i;
#ifdef MS
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cf"));
#else
static_assert(is_equal(__FUNCTION__, "cf"));
#endif
}
template <class T>
static void df(double f) {
(void)f;
#ifdef MS
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::df"));
#else
static_assert(is_equal(__FUNCTION__, "df"));
#endif
}
template <class T>
static constexpr void cdf(double f) {
(void)f;
#ifdef MS
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cdf"));
#else
static_assert(is_equal(__FUNCTION__, "cdf"));
#endif
}
};
}
void foo() {
test_func::inner::C<test_func::A>::f<char>(1);
test_func::inner::C<test_func::A>::cf<char>(1);
test_func::inner::C<test_func::A>::df<void>(1.0);
test_func::inner::C<test_func::A>::cdf<void>(1.0);
}
} // namespace test_func