[clang] [CLANG-CL] Remove the 'static' declaration specifier for _FUNCTION_ in (PR #128184)

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 21 07:15:50 PST 2025


https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/128184

MSVC mode.

>From bcf2a4708c3f9ae88f5fddafe02c95533601c887 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <Zahira.Ammarguellat at intel.com>
Date: Fri, 21 Feb 2025 07:14:02 -0800
Subject: [PATCH] [CLANG-CL] Remove the 'static' declaration specifier for
 _FUNCTION_ in MSVC mode.

---
 clang/lib/AST/Expr.cpp                 |  8 +++++--
 clang/test/SemaCXX/source_location.cpp | 31 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b747aa8df807d..14d0955503634 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -747,8 +747,12 @@ 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()) {
+        bool IsFunctionInMSVCCommpatEnv =
+            IK == PredefinedIdentKind::Function && LO.MSVCCompat;
+        if (ForceElaboratedPrinting && !IsFunctionInMSVCCommpatEnv)
+          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
 
 



More information about the cfe-commits mailing list