Skip to content

Commit 7358973

Browse files
authored
[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.
1 parent 59e0704 commit 7358973

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ Bug Fixes in This Version
251251
- Non-local variable and non-variable declarations in the first clause of a ``for`` loop in C are no longer incorrectly
252252
considered an error in C23 mode and are allowed as an extension in earlier language modes.
253253

254+
- Remove the ``static`` specifier for the value of ``_FUNCTION_`` for static functions, in MSVC compatibility mode.
255+
254256
Bug Fixes to Compiler Builtins
255257
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
256258

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
747747
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
748748
if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual)
749749
Out << "virtual ";
750-
if (MD->isStatic())
750+
if (MD->isStatic() && !ForceElaboratedPrinting)
751751
Out << "static ";
752752
}
753753

clang/test/SemaCXX/source_location.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,57 @@ TestClass<test_func::C> t2;
524524
TestStruct<test_func::S> t3;
525525
TestEnum<test_func::E> t4;
526526

527+
class A { int b;};
528+
namespace inner {
529+
template <class Ty>
530+
class C {
531+
public:
532+
template <class T>
533+
static void f(int i) {
534+
(void)i;
535+
#ifdef MS
536+
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f"));
537+
#else
538+
static_assert(is_equal(__FUNCTION__, "f"));
539+
#endif
540+
}
541+
template <class T>
542+
static constexpr void cf(int i) {
543+
(void)i;
544+
#ifdef MS
545+
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cf"));
546+
#else
547+
static_assert(is_equal(__FUNCTION__, "cf"));
548+
#endif
549+
}
550+
template <class T>
551+
static void df(double f) {
552+
(void)f;
553+
#ifdef MS
554+
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::df"));
555+
#else
556+
static_assert(is_equal(__FUNCTION__, "df"));
557+
#endif
558+
}
559+
template <class T>
560+
static constexpr void cdf(double f) {
561+
(void)f;
562+
#ifdef MS
563+
static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cdf"));
564+
#else
565+
static_assert(is_equal(__FUNCTION__, "cdf"));
566+
#endif
567+
}
568+
};
569+
}
570+
571+
void foo() {
572+
test_func::inner::C<test_func::A>::f<char>(1);
573+
test_func::inner::C<test_func::A>::cf<char>(1);
574+
test_func::inner::C<test_func::A>::df<void>(1.0);
575+
test_func::inner::C<test_func::A>::cdf<void>(1.0);
576+
}
577+
527578
} // namespace test_func
528579

529580

0 commit comments

Comments
 (0)