__FUNCTION__ - MS: string literal vs. GCC: string

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

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.

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.