code:
#include<iostream>
using namespace std;
int main()
{
size_t i = sizeof new int;
cout<<i;
}
In GCC compiler, working fine without any warning or error and printed output 8
.
But, in clang compiler, I got the following warning:
warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression]
size_t i = sizeof new int;
- Which one is true?
- Is
sizeof new int;
undefined behavior?
sizeof malloc(some_value)
which would not callmalloc()
and, if performed after#include <stdlib.h>
, would give a result equal tosizeof(void *)
. – Rourke