Czy specyfikacja C ++ określa kolejność operator newi konstruktor Aw new C(A()).
G ++ niech kolejność będzie A()-> new-> C(), ale clang ++ niech będzie new-> A()-> C().
Czy różnica jest spowodowana nieokreślonym zachowaniem?
g ++: 7.4.0 clang ++: 10.0.0
#include <iostream>
#include <cstdlib>
struct A {
A() {
std::cout << "call A()\n";
}
};
struct C {
C(A) {
std::cout << "call S()\n";
}
void *operator new(size_t s) {
std::cout << "call new()\n";
return malloc(s);
}
};
int main() {
void *p = new C(A());
}