Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the MSVC equivalent for -fno-char8_t?

In C++20 u8 string literals are based on the char8_t type. They deliberately do not convert to char const* any more:

const char* str = u8"Hall\u00f6chen \u2603"; // no longer valid in C++20

Of course, the ultimate goal when migrating to C++20 is to entirely go with the new behaviour (in the example above: change the type of str). However, because of 3rd party libraries, this is often not possible immediately.

The proposals that introduce and "remedy" char8_t anticipate that and mention that in clang and gcc there is the -fno-char8_t flag to switch back to the old behaviour (while still being able to enjoy other C++20 features).

The 2nd proposal sets up the expectation that Microsoft will follow and add a similar flag, but I was not able to find how to set it (at least in VS 2019, Version 16.4).

So does anyone know what the MSVC equivalent for -fno-char8_t is?

like image 822
Tobi Avatar asked Dec 13 '19 15:12

Tobi


People also ask

Does MSVC support C++ 20?

Compiler supportVisual Studio 2019 supports all C++20 features through its /std:c++latest option, as of version 16.10. 0. An option /std:c++20 to enable C++20 mode is added in version 16.11. 0.

Should I use MSVC or MinGW?

Is MinGW (MinGW-64) better than Cygwin in terms of MSVC alternative for creating Windows application? If your program will run only on Windows, then MinGW is likely the better choice. MinGW is designed to create Windows applications. It doesn't require users to install additional software to run your application.

Does Visual Studio use MSVC?

Microsoft Visual C++ Microsoft Visual C++ (MSVC) is a compiler for the C, C++ and C++/CX programming languages by Microsoft. MSVC is proprietary software; it was originally a standalone product but later became a part of Visual Studio and made available in both trialware and freeware forms.

What compiler does MSVC use?

Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.


1 Answers

Since 16.1, there is the conformance compiler flag /Zc:char8_t-. The minus tells the compiler to not use conformance mode here when using C++20. On the contrary, /Zc:char8_t can be used to enable it.

like image 111
Guillaume Racicot Avatar answered Sep 18 '22 18:09

Guillaume Racicot