[Bug c++/79600] New: [c++11] reinterpret_cast not working in enum class
smal.root at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Feb 19 20:09:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600
Bug ID: 79600
Summary: [c++11] reinterpret_cast not working in enum class
Product: gcc
Version: 7.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: smal.root at gmail dot com
Target Milestone: ---
Created attachment 40774
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40774&action=edit
source code
New compiler do not want to assign value to member of enum class and show
error:
1.cpp: In function 'int main()':
1.cpp:14:43: error: reinterpret_cast from integer to pointer
EnumMember = reinterpret_cast<uintptr_t>(&TEST_MACROS)
^~~~~~~~~~~~~
1.cpp:14:43: error: 'reinterpret_cast<Foo* {aka SFoo*}>(2048)' is not a
constant expression
1.cpp:14:58: error: enumerator value for 'EnumMember' is not an integer
constant
EnumMember = reinterpret_cast<uintptr_t>(&TEST_MACROS)
But value successfully assigned for regular variable.
avr-gcc-4.9.4 - compilation successful
avr-gcc-5.4.0 - compilation successful
avr-gcc-6.3.0 - compilation error
avr-gcc-7.0.1-20170219 - compilation error
I'll attach *.ii files for every gcc version.
Build string:
avr-g++ -save-temps -std=c++11 -Wall -Os -pedantic -mmcu=atxmega128a3u -c 1.cpp
-o 1.o && avr-g++ -std=c++11 -Wall -Os -mmcu=atxmega128a3u 1.o -o 1
Information about compilers
1.
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr/libexec/gcc/avr/4.9.4/lto-wrapper
Target: avr
Configured with: ../gcc-4.9.4/configure --prefix=/opt/toolchain/avr
--target=avr --disable-nls --enable-languages=c,c++ --disable-libssp
--enable-lto --with-isl
Thread model: single
gcc version 4.9.4 (GCC)
2.
5.4.0
Using built-in specs.
Reading specs from
/opt/toolchain/avr_5/lib/gcc/avr/5.4.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_5/libexec/gcc/avr/5.4.0/lto-wrapper
Target: avr
Configured with: ../gcc-5.4.0/configure --prefix=/opt/toolchain/avr_5
--disable-nls --disable-shared --target=avr --disable-install-libiberty
--disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions
--disable-linker-build-id --disable-werror --disable-__cxa_atexit
--enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object
--enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto
--enable-plugin --enable-shared --with-gnu-as --with-gnu-ld
--with-plugin-ld=ld.gold --with-system-zlib --with-isl
--enable-gnu-indirect-function
Thread model: single
gcc version 5.4.0 (GCC)
3.
6.3.0
Using built-in specs.
Reading specs from
/opt/toolchain/avr_6/lib/gcc/avr/6.3.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_6/libexec/gcc/avr/6.3.0/lto-wrapper
Target: avr
Configured with: ../gcc-6.3.0/configure --prefix=/opt/toolchain/avr_6
--disable-nls --disable-shared --target=avr --disable-install-libiberty
--disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions
--disable-linker-build-id --disable-werror --disable-__cxa_atexit
--enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object
--enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto
--enable-plugin --enable-shared --with-gnu-as --with-gnu-ld
--with-plugin-ld=ld.gold --with-system-zlib --with-isl
--enable-gnu-indirect-function
Thread model: single
gcc version 6.3.0 (GCC)
4.
trunk
Using built-in specs.
Reading specs from
/opt/toolchain/avr_trunk/lib/gcc/avr/7.0.1/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_trunk/libexec/gcc/avr/7.0.1/lto-wrapper
Target: avr
Configured with: ../gcc_trunk/configure --prefix=/opt/toolchain/avr_trunk
--disable-nls --disable-shared --target=avr --enable-languages=c,c++
--enable-lto --enable-plugin --with-isl
Thread model: single
gcc version 7.0.1 20170219 (experimental) (GCC)
----------------------------------------------------------------
Why do not to use version 4 or 5? ))
avr-gcc-4.9.4 generate file with size ~58kB. Nice, but not working.
avr-gcc-5.3.0 generate file with size ~74kB. Uncool.
More information about the Gcc-bugs
mailing list