Skip to content

Commit 23f9917

Browse files
authored
CXX-2629 Remove requirement to set /Zc:__cplusplus in MSVC flags (#924)
* remove /EHsc from msvc2017 evg flags * remove requirement for /Zc:__cplusplus * remove /Zc:__cplusplus from documented requirements Note option requirements for <= 3.7.0. Note /EHsc is required for <= 3.7.0. * remove /Zc:__cplusplus from example projects
1 parent 8988279 commit 23f9917

File tree

11 files changed

+18
-28
lines changed

11 files changed

+18
-28
lines changed

.mci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ variables:
4343
ubsan_cmake_flags: &ubsan_cmake_flags -DCMAKE_C_FLAGS="-Wall -Wextra -Wno-attributes -Werror -Wno-missing-field-initializers $ignore_deprecated" -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -fsanitize=undefined -fsanitize-blacklist=$(pwd)/etc/ubsan.ignorelist -fno-sanitize-recover=undefined -O1 -g -fno-omit-frame-pointer -Wall -Wextra -Wconversion -Wnarrowing -pedantic -Werror $ignore_deprecated"
4444
msvc2015_cmake_flags: &msvc2015_cmake_flags -DBOOST_ROOT=c:/local/boost_1_60_0
4545
msvc2015_generator: &msvc2015_generator Visual Studio 14 2015 Win64
46-
# The VS option /Zc:__cplusplus is necessary to build with VS2017's
47-
# native C++17 support. __cplusplus should indicate the standard of C++
48-
# the compiler supports. VS2017 erroneously reports it as 199711L
49-
# (instead of 201703L) without this option.
50-
# The VS option /EHsc is necessary to opt into C++ standard exception unwinding.
51-
# Without this option, some destructors may not be called in tests (CXX-2054).
52-
msvc2017_cmake_flags: &msvc2017_cmake_flags -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS="/Zc:__cplusplus /EHsc"
46+
msvc2017_cmake_flags: &msvc2017_cmake_flags -DCMAKE_CXX_STANDARD=17
5347
msvc2017_generator: &msvc2017_generator Visual Studio 15 2017 Win64
5448
code_coverage_cmake_flags: &code_coverage_cmake_flags -DENABLE_CODE_COVERAGE=ON
5549

docs/content/mongocxx-v3/installation/windows.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,34 @@ The example above assumes:
109109
* `libmongoc` is found in `C:\mongo-c-driver`.
110110
* `mongocxx` is to be installed into `C:\mongo-cxx-driver`.
111111

112-
For building with Visual Studio 2017 (without a C++17 polyfill), it is necessary to configure with
113-
an additional option, `/Zc:__cplusplus` to opt into the correct definition of `__cplusplus`
114-
([problem described here](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/)):
112+
To build with Visual Studio 2017 without a C++17 polyfill, configure as follows:
115113

116114
```sh
117115
'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \
118116
-G "Visual Studio 15 2017 Win64" \
119117
-DCMAKE_CXX_STANDARD=17 \
120-
-DCMAKE_CXX_FLAGS="/Zc:__cplusplus" \
121118
-DCMAKE_PREFIX_PATH=C:\mongo-c-driver \
122119
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \
123120
```
124121

125122
For details on how to install libmongoc for Windows, see the
126123
[mongoc Windows installation instructions](http://mongoc.org/libmongoc/current/installing.html#building-windows).
127124

125+
#### Configuring with `mongocxx` 3.7.0 and older
126+
127+
To build versions 3.7.0 and older without a C++17 polyfill, it is necessary to configure with additional options:
128+
- `/Zc:__cplusplus` to opt into the correct definition of `__cplusplus` ([problem described here](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/))
129+
- `/EHsc` to enable recommended [exception handling behavior](https://learn.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=msvc-170).
130+
131+
```sh
132+
'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \
133+
-G "Visual Studio 15 2017 Win64" \
134+
-DCMAKE_CXX_STANDARD=17 \
135+
-DCMAKE_CXX_FLAGS="/Zc:__cplusplus /EHsc" \
136+
-DCMAKE_PREFIX_PATH=C:\mongo-c-driver \
137+
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \
138+
```
139+
128140
#### Configuring with `mongocxx` 3.1.x or 3.0.x
129141

130142
Instead of the `-DCMAKE_PREFIX_PATH` option, users must specify the `libmongoc` installation

examples/projects/bsoncxx/cmake-deprecated/shared/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4646
find_package(Boost 1.56.0 REQUIRED)
4747
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
4848
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
49-
else ()
50-
target_compile_options(hello_bsoncxx PRIVATE /Zc:__cplusplus)
5149
endif ()
5250
endif()
5351

examples/projects/bsoncxx/cmake-deprecated/static/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4646
find_package(Boost 1.56.0 REQUIRED)
4747
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
4848
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
49-
else ()
50-
target_compile_options(hello_bsoncxx PRIVATE /Zc:__cplusplus)
5149
endif ()
5250
endif()
5351

examples/projects/bsoncxx/cmake/shared/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5050
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
5151
endif()
5252
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
53-
else ()
54-
target_compile_options(hello_bsoncxx PRIVATE /Zc:__cplusplus)
5553
endif ()
5654
endif()
5755

examples/projects/bsoncxx/cmake/static/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5050
target_link_libraries(hello_bsoncxx PRIVATE Boost::boost)
5151
endif()
5252
target_compile_definitions(hello_bsoncxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
53-
else ()
54-
target_compile_options(hello_bsoncxx PRIVATE /Zc:__cplusplus)
5553
endif ()
5654
endif()
5755

examples/projects/mongocxx/cmake-deprecated/shared/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4646
find_package(Boost 1.56.0 REQUIRED)
4747
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
4848
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
49-
else ()
50-
target_compile_options(hello_mongocxx PRIVATE /Zc:__cplusplus)
5149
endif ()
5250
endif()
5351

examples/projects/mongocxx/cmake-deprecated/static/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4646
find_package(Boost 1.56.0 REQUIRED)
4747
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
4848
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
49-
else ()
50-
target_compile_options(hello_mongocxx PRIVATE /Zc:__cplusplus)
5149
endif ()
5250
endif()
5351

examples/projects/mongocxx/cmake/shared/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5050
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
5151
endif()
5252
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
53-
else ()
54-
target_compile_options(hello_mongocxx PRIVATE /Zc:__cplusplus)
5553
endif ()
5654
endif()
5755

examples/projects/mongocxx/cmake/static/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5656
target_link_libraries(hello_mongocxx PRIVATE Boost::boost)
5757
endif()
5858
target_compile_definitions(hello_mongocxx PRIVATE BSONCXX_POLY_USE_BOOST=ON)
59-
else ()
60-
target_compile_options(hello_mongocxx PRIVATE /Zc:__cplusplus)
6159
endif ()
6260
endif()
6361

src/bsoncxx/stdx/make_unique.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ using ::boost::make_unique;
4848
BSONCXX_INLINE_NAMESPACE_END
4949
} // namespace bsoncxx
5050

51-
#elif __cplusplus >= 201402L
51+
#elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
5252

5353
#include <memory>
5454

0 commit comments

Comments
 (0)