-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential ODR violation linking C++14 with C++17+ TUs that use container emplace functions #4962
Comments
IIRC our motivation for conditionally making the change was to avoid any possible breakage of C++14 code in the wild. Given the potential for ODR violations, I now think it would be preferable to make the change unconditional and deal with any breakage. I'll mark this "decision needed" so we can determine if the other maintainers agree. Feel free to comment here. |
Looks like that it's too eager to use |
Yes, it looks like #4963's concrete return types address the ODR problem since we encode return types in mangled member names:
There's no need to risk breaking (very weird) C++14 code. |
The
emplace_front
andemplace_back
members of our containers andemplace
members of our container adaptors use a "tricky" technique to implement the C++17 change that had these functions return a reference to the newly emplaced element. We changed the declare return types fromvoid
todecltype(auto)
, and ended each function with e.g.:This approach has the nice property that the functions continue to return
void
in C++14 mode as they did before the change.However, the mangled name of the functions is the same in both language modes (credit to STL):
potentially creating an ODR violation when linking C++14 and C++17 TUs that instantiate the same
emplace
function. If a C++17 TU uses the returned reference, but the linker chooses the instantiation from a C++14 TU that returns no such reference, terrible things will happen.The text was updated successfully, but these errors were encountered: