[Bug c++/103954] GCC did not generate correct code for template function with O2
woodhead99 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jan 10 01:00:25 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103954
--- Comment #2 from Ming Zhi <woodhead99 at gmail dot com> ---
thanks for your great answer! I did not know the effect of strict aliasing till
today. It looks I need to update my knowledge base about c++ right now.
Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: pinskia at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
Sent: Monday, January 10, 2022 12:22:24 AM
To: woodhead99@gmail.com <woodhead99@gmail.com>
Subject: [Bug c++/103954] GCC did not generate correct code for template
function with O2
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
enum EnumSeriProto : guint32
{
seriNone = 0,
seriRidl = 1,
seriPython = 2,
seriJava = 3,
seriInvalid = 4
};
....
EnumSeriProto dwSeriProto = seriNone;
ret = GetSeriProto( pResp, dwSeriProto );
...
return oCfg.GetIntProp(
propSeriProto, ( guint32& )dwSeriProto );
...
gint32 GetIntProp( gint32 iProp, guint32& val ) const
{
return GetPrimProp( iProp, val );
}
...
template< typename PrimType, ... >
gint32 GetPrimProp(
gint32 iProp, PrimType& val ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -
# 1212 "/usr/local/include/rpcf/configdb.h" 3 4
14
# 1212 "/usr/local/include/rpcf/configdb.h"
;
auto pdb2 = static_cast< const CConfigDb2* const >( m_pConstCfg );
do{
const Variant* p =
pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -
# 1220 "/usr/local/include/rpcf/configdb.h" 3 4
2
# 1220 "/usr/local/include/rpcf/configdb.h"
;
break;
}
val = *p;
}while( 0 );
return ret;
}
enum types don't alias the underlaying type and therefore this code is
undefined at runtime.
Use Either a memcpy (or an union) inside GetSeriProto or use
-fno-strict-aliasing.
--
You are receiving this mail because:
You reported the bug.
More information about the Gcc-bugs
mailing list