{"id":18805,"date":"2018-04-09T10:00:02","date_gmt":"2018-04-09T17:00:02","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=18805"},"modified":"2022-06-23T20:58:46","modified_gmt":"2022-06-23T20:58:46","slug":"msvc-now-correctly-reports-__cplusplus","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/msvc-now-correctly-reports-__cplusplus\/","title":{"rendered":"MSVC now correctly reports __cplusplus"},"content":{"rendered":"<p>The MSVC compiler\u2019s definition of the <code>__cplusplus<\/code> predefined macro leaps ahead 20 years in Visual Studio 2017 version 15.7 Preview 3. This macro has stubbornly remained at the value &#8220;199711L&#8221;, indicating (erroneously!) that the compiler conformed to the C++98 Standard. Now that <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-standards-conformance-from-microsoft\/\">our conformance catch-up work is drawing to a close<\/a> we\u2019re updating the <code>__cplusplus<\/code> macro to reflect the true state of our implementation. The value of the <code>__cplusplus<\/code> macro doesn\u2019t imply that we no longer have any conformance bugs. It\u2019s just that the new value is much more accurate than always reporting &#8220;199711L&#8221;.<\/p>\n<h3>\/Zc:__cplusplus<\/h3>\n<p>You need to compile with the <code>\/Zc:__cplusplus<\/code> switch to see the updated value of the <code>__cplusplus<\/code> macro. We tried updating the macro by default and discovered that a lot of code doesn\u2019t compile correctly when we change the value of <code>__cplusplus<\/code>. We\u2019ll continue to require use of the <code>\/Zc:__cplusplus<\/code> switch for all minor versions of MSVC in the 19.xx family.<\/p>\n<p>The version reported by the <code>__cplusplus<\/code> macro also depends upon the standard version switch used. If you\u2019re compiling in C++14 mode the macro will be set to &#8220;201402L&#8221;. If you compile in C++17 mode the macro will be set to &#8220;201703L&#8221;. And <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/standards-version-switches-in-the-compiler\">the <code>\/std:c++latest<\/code> switch<\/a>, used to enable features from the Standard currently in development, sets a value that is more than the current Standard. This chart shows the values of the <code>__cplusplus<\/code> macro with different switch combinations:<\/p>\n<table>\n<tbody>\n<tr>\n<th>\/Zc:__cplusplus switch<\/th>\n<th>\/std:c++ switch<\/th>\n<th>__cplusplus value<\/th>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus<\/code><\/td>\n<td>Currently defaults to C++14<\/td>\n<td>201402L<\/td>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus<\/code><\/td>\n<td><code>\/std:c++14<\/code><\/td>\n<td>201402L<\/td>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus<\/code><\/td>\n<td><code>\/std:c++17<\/code><\/td>\n<td>201703L<\/td>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus<\/code><\/td>\n<td><code>\/std:c++latest<\/code><\/td>\n<td>201704L<\/td>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus-<\/code> (disabled)<\/td>\n<td>Any value<\/td>\n<td>199711L<\/td>\n<\/tr>\n<tr>\n<td><code>Zc:__cplusplus<\/code> not specified<\/td>\n<td>Any value<\/td>\n<td>199711L<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note that the MSVC compiler does not, and never will, support a C++11, C++03, or C++98 standards version switch. Also, the value of the <code>__cplusplus<\/code> macro is not affected by <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2016\/11\/16\/permissive-switch\">the \/permissive- switch<\/a>.<\/p>\n<p>We\u2019re updating IntelliSense to correctly reflect the value of <code>__cplusplus<\/code> when compiling with MSVC. We expect IntelliSense to be correct in the next preview of 15.7.<\/p>\n<h3>_MSC_VER and _MSVC_LANG<\/h3>\n<p>For finer-grained detection of changes in the MSVC toolset you can <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2016\/10\/05\/visual-c-compiler-version\">continue to use the <code>_MSC_VER<\/code> predefined macro<\/a>. We have updated the value of this built-in macro with every toolset update in Visual Studio 2017 and will continue to do so.<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/preprocessor\/predefined-macros\">The <code>_MSVC_LANG<\/code> predefined macro<\/a> continues to report the Standard version switch regardless of the value of <code>\/Zc:__cplusplus<\/code>. <code>_MSVC_LANG<\/code> is set whether or not the <code>\/Zc:__cplusplus<\/code> option is enabled. When <code>\/Zc:__cplusplus<\/code> is enabled, <code>__cplusplus == _MSVC_LANG<\/code>.<\/p>\n<h3>Please look for usage in your code<\/h3>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/search.html?f=&amp;type=question+OR+problem&amp;type=question+OR+problem&amp;c=&amp;redirect=search%2Fsearch&amp;sort=relevance&amp;q=__cplusplus\">We\u2019ve heard repeatedly from developers<\/a> as we\u2019ve gotten closer to complete conformance that we need to update the value of this macro. Now we need help from you. We tried to define <code>__cplusplus<\/code> correctly by default but discovered that a lot of code expects MSVC to always set the macro to &#8220;199711L&#8221;.<\/p>\n<p>Please take a moment to search your code for references to <code>__cplusplus<\/code> and compile with the <code>\/Zc:__cplusplus<\/code> switch enabled. Your code might be using this macro to determine if it\u2019s being compiled with MSVC or Clang in MSVC-emulation mode. If your codebase is really old, it might be using this macro to determine if you\u2019re using VC++ 6.0! Take a moment to compile with this switch enabled. We need the ecosystem to move forward so we can set <code>__cplusplus<\/code> accurately by default.<\/p>\n<h3>In closing<\/h3>\n<p>As always, we welcome your feedback. We can be reached via the comments below or via email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>).<\/p>\n<p>If you encounter other problems with MSVC in Visual Studio 2017 please let us know through <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Help &gt; Report A Problem in the product<\/a>, or via <a href=\"https:\/\/developercommunity.visualstudio.com\/topics\/C%2B%2B.html\">Developer Community<\/a>. Let us know your suggestions through <a href=\"https:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio-2015\/category\/30937-languages-c\">UserVoice<\/a>. You can also find us on Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>) and Facebook (<a href=\"https:\/\/www.facebook.com\/msftvisualcpp\">msftvisualcpp<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The MSVC compiler\u2019s definition of the __cplusplus predefined macro leaps ahead 20 years in Visual Studio 2017 version 15.7 Preview 3. This macro has stubbornly remained at the value &#8220;199711L&#8221;, indicating (erroneously!) that the compiler conformed to the C++98 Standard. Now that our conformance catch-up work is drawing to a close we\u2019re updating the __cplusplus [&hellip;]<\/p>\n","protected":false},"author":312,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-18805","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>The MSVC compiler\u2019s definition of the __cplusplus predefined macro leaps ahead 20 years in Visual Studio 2017 version 15.7 Preview 3. This macro has stubbornly remained at the value &#8220;199711L&#8221;, indicating (erroneously!) that the compiler conformed to the C++98 Standard. Now that our conformance catch-up work is drawing to a close we\u2019re updating the __cplusplus [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/312"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=18805"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18805\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=18805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=18805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=18805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}