[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 05:22:05 PST 2024


================
@@ -721,10 +722,21 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
     return std::string(Out.str());
   }
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
-    if (IK != PredefinedIdentKind::PrettyFunction &&
+    const auto &LO = Context.getLangOpts();
+    bool isFuncOrFunctionInNonMSVCCompatEnv =
+        ((IK == PredefinedIdentKind::Func ||
+          IK == PredefinedIdentKind ::Function) &&
+         !LO.MSVCCompat);
+    bool isLFunctionInMSVCCommpatEnv =
+        IK == PredefinedIdentKind::LFunction && LO.MSVCCompat;
+    bool isFuncOrFunctionOrLFunctionOrFuncDName =
+        IK != PredefinedIdentKind::PrettyFunction &&
         IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
         IK != PredefinedIdentKind::FuncSig &&
-        IK != PredefinedIdentKind::LFuncSig)
+        IK != PredefinedIdentKind::LFuncSig;
+    if ((ForceElaboratedPrinting &&
+         (isFuncOrFunctionInNonMSVCCompatEnv || isLFunctionInMSVCCommpatEnv)) ||
+        !ForceElaboratedPrinting && isFuncOrFunctionOrLFunctionOrFuncDName)
----------------
AaronBallman wrote:

```suggestion
        (!ForceElaboratedPrinting && isFuncOrFunctionOrLFunctionOrFuncDName))
```
You may need this to avoid diagnostics about mixed `&&` and `||` operators.

https://github.com/llvm/llvm-project/pull/84014


More information about the cfe-commits mailing list