https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82224
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Alexander Cherepanov from comment #6)
> And with allocated memory (C; add placement new's for C++):
>
> ----------------------------------------------------------------------
> #include <stdlib.h>
> #include <string.h>
> #include <stdio.h>
>
> static long test(long *px, long long *py, void *pu)
> {
> *px = 0;
> *py = 1;
>
> // change effective type from long long to long
> long tmp;
> memcpy(&tmp, pu, sizeof(tmp));
> memcpy(pu, &tmp, sizeof(tmp));
I believe this one is invalid - memcpy transfers the dynamic
type and *pu is currently 'long long'. So it's either not
changing the dynamic type because, well, the type transfers
through 'tmp' or you are accessing 'tmp' with declared type
long as 'long long'.
> return *px;
> }
>
> int main(void)
> {
> void *p = malloc(10);
>
> printf("%ld\n", test(p, p, p));
> }
> ----------------------------------------------------------------------
>
> Results:
>
> ----------------------------------------------------------------------
> $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
> 1
> $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
> 0
> ----------------------------------------------------------------------
>
> gcc version: gcc (GCC) 8.0.0 20171023 (experimental)