configure: force -fno-strict-aliasing for C++ modules using COM objects

This avoids potential compiler optimizations when casting to void** when using
IID_PPV_ARGS or WRL.

If the option is not supported we fail the configure as many important C++
modules may not work as expected due to pointer aliasing. In practice this
should never happen as GCC for mingw-w64 and Clang support this correctly.
This commit is contained in:
Steve Lhomme 2021-11-16 11:27:15 +01:00 committed by Hugo Beauzée-Luyssen
parent 5140d9869f
commit 7a776a79ff
1 changed files with 11 additions and 0 deletions

View File

@ -388,6 +388,16 @@ AC_ARG_ENABLE([winstore_app],
vlc_winstore_app=0
AS_IF([test "${SYS}" = "mingw32"],[
LIBCOM="-lole32 -loleaut32"
AC_LANG_PUSH(C++)
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [
LIBCOMCXXFLAGS="-fno-strict-aliasing"
],[
# fno-strict-aliasing is necessary for WRL and IID_PPV_ARGS to work safely
# MSVC doesn't have this option but doesn't do pointer aliasing, so it
# should work too
AC_MSG_ERROR([-fno-strict-aliasing is necessary for Windows C++ modules])
])
AC_LANG_POP(C++)
AS_IF([test "${enable_winstore_app}" = "yes"], [
vlc_winstore_app=1
LIBCOM="-loleaut32"
@ -400,6 +410,7 @@ AS_IF([test "${SYS}" = "mingw32"],[
AC_DEFINE([VLC_WINSTORE_APP], [1], [Define to 1 if building for Windows Store.])
],[])
AC_SUBST([LIBCOM])
AC_SUBST([LIBCOMCXXFLAGS])
])
vlc_build_pdb=0