[CXX-2055] Set /EHsc when building on Visual Studio Created: 18/Jun/20 Updated: 27/Oct/23 Resolved: 12/Jan/23 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Kevin Albertson | Assignee: | Unassigned |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Description |
|
When running tests on Visual Studio 2017 in The compiler output when building the test_driver target produced the multiple warnings like this one:
Sure enough, setting /EHcs for building tests resolved the issue. However, it is not clear to me why this is not the default behavior for C++ exception handling, and whether we need to make a change in our documentation or cmake scripts to account for this. This page indicates that /EHcs should be the default.
Though this page indicates that the default behavior may only partially support standard C++ exception handling:
Additionally, this StackOverflow answer indicates that crossing the extern C boundary requires setting /EHs. This may be relevant to the implementation of the with_transaction helper, which calls a C++ supplied callback through a libmongoc function. https://github.com/mongodb/mongo-cxx-driver/blob/master/src/mongocxx/client_session.hpp#L144-L166
|
| Comments |
| Comment by Kevin Albertson [ 12/Jan/23 ] | ||||||
|
Configuring the C++ driver version 3.7.0 and older with C++17 in Visual Studio must also include the /EHsc flag:
The installation documentation incorrectly did not include /EHsc. /EHsc is the documented default for the exception handling model. Omitting the /EHsc may result in incorrect stack unwinding behavior. Omitting the /EHsc flag results in an Internal Compiler error when building tests on Visual Studio 2022. In 3.7.1 and newer, this is resolved by | ||||||
| Comment by Kevin Albertson [ 18/Jun/20 ] | ||||||
|
Note, the server sets this as well: https://github.com/mongodb/mongo/blob/v4.2/SConstruct/#L1644-L1646 |