Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

improper value of '__cplusplus' definition in ICC 2017

sav
Novice
1,331 Views

Hello, everyone,

For Qt builds using ICC on Windows with C++14 support enabled got error:

Feature 'c++14' was enabled, but the pre-condition 'features.c++11 && tests.c++14' failed

After some investigations found, that ICC failed test:

#if __cplusplus > 201103L
#else
#  error "__cplusplus must be > 201103L (the value of C++11)"
#endif

during configuration. While mingw-w64 passes it successfully.

The source of error is value of '__cplusplus' definition, which is 199711L for ICC, while 201402L for mingw-w64.

Using '-Qstd=c++14' or '-D__cplusplus=201402L' compiler keys didn't solve this issue.

 

Since ICC 2017 declare support of C++14, it's expected, that '__cplusplus' definition contain appropriate value. As mingw-w64 do. Is it possible to set '__cplusplus' value according to declared ICC features? So there won't be needed to hack various sources in order to skip such C++14 compliance tests.

 

 


Environment:

  • Windows 10 x64,
  • IPSXE 2017 Update 4,
  • VS 2015 Update 3,
  • Qt-5.9.

 


Alexander

 

 

0 Kudos
1 Solution
Judith_W_Intel
Employee
1,331 Views

 

I am currrently in the process of adding the new /Zc:___cplusplus switch to our Windows icl compiler, unfortunately it is past code freeze for 18.0 update 2 but it should be in 18.0 update 3 and the second beta of 19.0.

This is described here:

https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/

Judy

View solution in original post

0 Kudos
7 Replies
TimP
Honored Contributor III
1,331 Views

As far as I can see, __cplusplus is inherited from MSVC++, so it might depend on which Visual Studio version is active.  However, a brief google search indicates that Microsoft has declined to advance it beyond 201103, even in VS2017.  Probably this indicates that Microsoft admits their support for newer standards is incomplete; by inheritance, the same would be true of ICL.

I didn't succeed in finding where it is set in VS2017 (which is organized entirely different from VS2015).

0 Kudos
sav
Novice
1,331 Views

Thank you, Tim, for a quick response.

But since ICC 2017 declare C++14 support, shouldn't it redefine '__cplusplus' according to implemented C++ Language features?

If not, how C++14 tests, like mentioned in 1st post, should be implemented in order to detect C++ Language support correctly? Yet again, mingw-w64 has no such troubles.

Alexander

 

0 Kudos
Judith_W_Intel
Employee
1,331 Views

 

No. In order to be compatible with the reference compiler on the system (on Windows this is MSVC++) we must set all macros to have the same value. This is important for example in ensuring we preprocess the system headers the same way as the reference compiler (since we don't have our own system headers).

The Intel compiler has implemented feature macros which might solve the problem.

See http://en.cppreference.com/w/cpp/experimental/feature_test

for examples such as __cpp_constexpr, etc.

Example:

#if __cpp_constexpr
// constexpr keyword implemented
#endif

Judy

0 Kudos
sav
Novice
1,331 Views

MSVC 2017 15.7 introduced '-Zc:__cplusplus' flag (see announce), which allows to set a proper value of '__cplusplus' definition for C++14, C++17 and later language support.

Can this flag be introduced in Windows ICC too?

Best,

Alexander

 

0 Kudos
TimP
Honored Contributor III
1,331 Views

ICL couldn't support this until a release following a stable MSVC++ release (not preview).  You have always had the option to override and set a new value of __cplusplus e.g. -U__cplusplus -D__cplusplus=201402L

0 Kudos
sav
Novice
1,331 Views

MSVC Developers announced, that MSVC 2017 version 15.7 Preview 3 available for download and shares link to related blog: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/

So introduction of -Zc:__cplusplus switch in the next MSVC release is imminent.

 

Best,

Alexander

 

0 Kudos
Judith_W_Intel
Employee
1,332 Views

 

I am currrently in the process of adding the new /Zc:___cplusplus switch to our Windows icl compiler, unfortunately it is past code freeze for 18.0 update 2 but it should be in 18.0 update 3 and the second beta of 19.0.

This is described here:

https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/

Judy

0 Kudos
Reply