[CXX-717] Add C++ compile-time standard detection Created: 22/Oct/15 Updated: 04/Oct/16 Resolved: 09/Sep/16 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | Implementation |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Tim Niemueller | Assignee: | David Golden |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | legacy-cxx, pull-request | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
The driver crashes badly if the library is linked to code not compiled with the same C++ standard level. For instance, if the driver is compiled with C++98 (still the default on GCC 5), but some code using it with C++11, the driver will crash. The header could be extended to detect this at run-time. For example, version.h.in could contain a macro to specify the C++ version used during compilation. Then, another macro evaluated on inclusion verifies that this version matches the currently used standard. If not, in #error can be thrown. |
| Comments |
| Comment by David Golden [ 09/Sep/16 ] |
|
I'm cleaning up long-open tickets. Given current priorities and backlog, we don't plan to commit resources to this. Rather than leaving it open, I'm going to mark it "Won't Fix" and close it. |
| Comment by Andrew Morrow (Inactive) [ 23/Oct/15 ] |
|
Hi timn - I don't disagree that it could be helpful. Just that it will require some careful attention to make sure that it doesn't cause more problems than it solves, and that the implementation isn't too complex or fragile. We need to both make things simple for people and not break things in surprising or confusing ways for the simple cases. It is definitely something we will take under consideration. |
| Comment by Tim Niemueller [ 23/Oct/15 ] |
|
It's a start and one that would have saved me an hour of searching... We can further constrain it only to be used on GCC (and it seems even GCC 4.7 is required as earlier versions simply define __cplusplus to 1 instead of the standard versions number). We can then grow the checks from there and adapt them as authors come along different compilers. |
| Comment by Andrew Morrow (Inactive) [ 22/Oct/15 ] |
|
timn - Thanks for the PR. The reason that I think it needs some consideration is that the value of the __cplusplus macro isn't truly reliable. Not all compilers implement it, and those that do don't necessarily adjust it as intended. Furthermore, GCC actually doesn't break ABI between C++03 and C++98 by default, unless you opt in to the new std::basic_string ABI. It is also unclear to me what if any ABI changes exist on the clang side, or between C++11 and C++14. Furthermore, this doesn't solve all of the ABI problems you can run into: building the driver against libc++ but boost against libstdc++ is a common one. Most of the time, the real problem is that boost doesn't offer a consistent ABI between language versions. |
| Comment by Tim Niemueller [ 22/Oct/15 ] |
|
It's actually not that hard. I have created a pull request https://github.com/mongodb/mongo-cxx-driver/pull/350 that implements this. Have a look if you find it suitable. |
| Comment by Andrew Morrow (Inactive) [ 22/Oct/15 ] |
|
timn - Thanks, that is an interesting suggestion but will require some thought to get right. It is a frequent source of difficulty, so I agree that catching it deterministically would be good. |