[cfe-dev] [llvm-dev] __FUNCTION__ - MS: string literal vs. GCC: string

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 15 15:57:46 PDT 2021


You can use this:

  #define WIDEN(x) L##x
  const wchar_t *f() { return WIDEN(__FUNCTION__); }

or more simply

  const wchar_t *f() { return L__FUNCTION__; }

In addition to supporting __FUNCTION__, Clang also provides L__FUNCTION__
as a built-in wide string. You'll need to either build for Windows or
enable -fms-extensions for this to be available.

I'm not sure what the history is here -- I can't find a version of MSVC
that allows L__FUNCTION__, so I'm not sure why this feature is under
-fms-extensions rather than simply being available by default as a Clang
extension. MSVC instead expects L"" __FUNCTION__ to be used to get a wide
version.

On Wed, 15 Sept 2021 at 13:39, David Blaikie via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> this'd be more suitable on cfe-dev (moving to cfe-dev, llvm-dev to bcc) -
> though might present some challenges in compatibility with GCC if GCC's
> doing it differently. I guess in ms-mode (clang-cl) it should/could be done
> in the MS-way.
>
> On Wed, Sep 15, 2021 at 2:59 AM chiasa.men via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Is there a way to tell clang to adapt to the microsoft way of defining
>> __FUNCTION__ as string literal and not as string?
>>
>> I stumbled upon this problem and am obviously not alone:
>>
>>
>> https://stackoverflow.com/questions/4773941/wide-version-of-function-on-linux/51381572#51381572
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210915/4226768b/attachment.html>


More information about the cfe-dev mailing list