Created
October 5, 2014 08:35
-
-
Save pervognsen/d1c7b3a183aa6352164c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In new(p) T(x) the C++ standard requires that placement new performs a null pointer check on p. | |
Unfortunately, this can add a pointless conditional to inner loops that use dynamic arrays implemented | |
in C++ via placement new. I don't expect the optimizer to perform a global analysis to conclude that p | |
can never be null, so I have to help it on its way. However, none of these three tricks convince Clang 3.5: | |
new(&*p) T(x); | |
(void) *p; | |
new(p) T(x); | |
if (!p) __builtin_unreachable(); | |
new(p) T(x); | |
Does anyone have a better idea? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment