Why does placement new depend on #include <iostream>
?
Sounds absurd? Well, this code only compiles if incommenting the include:
// #include <iostream>
struct Alignas { void* ptr; };
alignas(Alignas) static char storage[sizeof(Alignas)];
int main() { new(storage) Alignas; }
Gcc error (same with Clang):
alignas.cpp:7:27: error: no matching function for call to ‘operator new(sizetype, char [8])’
7 | int main() { new(storage) Alignas; }
| ^~~~~~~
<built-in>: note: candidate: ‘void* operator new(long unsigned int)’
<built-in>: note: candidate expects 1 argument, 2 provided
<built-in>: note: candidate: ‘void* operator new(long unsigned int, std::align_val_t)’
<built-in>: note: no known conversion for argument 2 from ‘char [8]’ to ‘std::align_val_t’
Looks like none of the candidates are the placement new. As if my placement-new expression isn't recognized. Unless I include that header, which is completely absurd, as it's a language feature.
EDIT:
It was absurd to me, as I've of course read the documentation on cppreference.com (which covers placement new), and the header deps listed there is none.