# set(CMAKE\_CXX\_STANDARD) should set /Zc:\_\_cplusplus for MSVC

**URL:** https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876
**Category:** Code
**Created:** [September 21, 2020, 6:25pm UTC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876 "2020-09-21T18:25:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [September 21, 2020, 6:25pm UTC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876/1 "2020-09-21T18:25:22Z")

</div>

It appears that doing (say) `set(CMAKE_CXX_STANDARD 17)` when targeting MSVC will set the `/std:c++17` flag, but not (also) the MS-specific `/Zc: __cplusplus` flag; this is unfortunate, because MSVC explicitly sets `__ cplusplus` to 199711L in all cases when `/Zc:cplusplus` is unspecified. (See [https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-\_\_cplusplus/](https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/)).

While this is arguably a bad decision on the part of MSVC, CMake should just quietly work around it by setting both of these flags, to ensure \_\_cplusplus has an accurate value.

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [September 21, 2020, 8:04pm UTC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876/2 "2020-09-21T20:04:46Z")

</div>

It seems this has been raised on Gitlab in issue #18837:

[https://gitlab.kitware.com/cmake/cmake/-/issues/18837](https://gitlab.kitware.com/cmake/cmake/-/issues/18837)

Quoting @brad.king’s comment in that issue:

> Some other property could be added for this. As mentioned above a policy would be needed to change its default.
> 
> For now I think `target_compile_options` is a reasonable workaround.

---

<div class="post-metadata">

### Author: ![eyalroz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eyalroz/32/3246_2.png) [@eyalroz](https://discourse.cmake.org/u/eyalroz)
#### Post date: [April 17, 2023, 5:53pm UTC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876/3 "2023-04-17T17:53:33Z")

</div>

I don’t believe it is a reasonable workaround, because it requires the CMakeLists to be specifically aware of this issue with MSVC. The CMakeLists author’s intent is expressed clearly when a standard is set. In fact, @brad.king pretty much said so on the issue page.
