Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

zahiraam
Copy link
Contributor

@zahiraam zahiraam commented Feb 21, 2025

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.

@zahiraam zahiraam changed the title [CLANG-CL] Remove the 'static' declaration specifier for _FUNCTION_ in [CLANG-CL] Remove the 'static' specifier for _FUNCTION_ in MSVC mode. Feb 21, 2025
@zahiraam zahiraam marked this pull request as ready for review February 21, 2025 18:33
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)

Changes

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&lt;class A&gt;::f
__FUNCTION__ static inner::C&lt;class A&gt;::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 --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
 
 

@zahiraam zahiraam requested a review from cor3ntin February 24, 2025 12:23
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit.

Please be sure to add a release note to clang/docs/ReleaseNotes.rst for the fix. Also, please add a test for constexpr (I believe we handle that correctly, but we might as well make sure we handle all the storage class specifiers at once).

Comment on lines 750 to 753
if (MD->isStatic()) {
if (!ForceElaboratedPrinting)
Out << "static ";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (MD->isStatic()) {
if (!ForceElaboratedPrinting)
Out << "static ";
}
if (MD->isStatic() && !ForceElaboratedPrinting)
Out << "static ";

@zahiraam zahiraam merged commit 7358973 into llvm:main Mar 6, 2025
12 checks passed
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants