简体   繁体   中英

c++17 language extension and std:c++17 flag

I'm confused by different errors I have in Visual Studio 2017 (version 15.9.11):

'if constexpr' is a C++17 language extension

and

language feature 'structured bindings' requires compiler flag '/std:c++17'

I know that adding /std:c++17 flag will solve these issues but why are there two different messages? What is a difference between language extension and a compiler flag requirement?

I am more interested about this thing, because I'm writing a game in Unreal Engine 4.24 I can use 'if constexpr', but I can't use 'structured bindings' even though I'm using the same compiler.

Why?

if constexpr is an exceedingly useful langauge construct from C++17. It's very handy for implementing, for example, many optimizations within the standard library.

As such, when Visual Studio 15.3 initially implemented if constexpr , it was used liberally in their standard library implementation even when compiled in C++14 mode. But since much of that code is in headers which, as far as the compiler is concerned, is part of your source code, that means you get to use it too. To allow for that, they made using if constexpr from C++14 a warning rather than an error, a warning they disabled within their headers with #pragma s.

However, despite MSVC's documentation calling it a warning, it is issued by the compiler as a error , which can be suppressed.

The difference in wording between these two conditions is therefore likely to be born of the fact that the if constexpr "error" is considered to be a "warning", despite presenting itself as an "error" by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM