[Bug c++/82326] New: static_cast for vector extension not working?
gcc-bugs at marehr dot dialup.fu-berlin.de
gcc-bugzilla@gcc.gnu.org
Tue Sep 26 13:51:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82326
Bug ID: 82326
Summary: static_cast for vector extension not working?
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
Target Milestone: ---
My problem is the following:
```
// main.cpp
#include <cstdint>
#include <x86intrin.h>
using int32x4_t = int32_t __attribute__ ((__vector_size__(16)));
using uint32x4_t = uint32_t __attribute__ ((__vector_size__(16)));
int main()
{
int32x4_t a{-1, 0, 1, 2};
// invalid static_cast from type ‘int32x4_t {aka __vector(4) int}’
// to type ‘uint32x4_t {aka __vector(4) unsigned int}
uint32x4_t b = static_cast<uint32x4_t>(a); // fails with above message
uint32x4_t c = reinterpret_cast<uint32x4_t>(a); // works
// invalid static_cast from type ‘int32x4_t {aka __vector(4) int}’
// to type ‘__m128i {aka __vector(2) long long int}
__m128i d = static_cast<__m128i>(a); // fails with above message
__m128i e = reinterpret_cast<__m128i>(a); // works
return 0;
}
```
> g++ -msse4 main.cpp -o main
Why is a static_cast not working?
This is a hassle, because different compilers support different syntaxes.
* gcc allows only reinterpret_cast and C-style casts
* clang allows both static_cast and reinterpret_cast and C-style casts
* icc (Intel Compiler) allows only static_cast and C-style casts
Thank you!
More information about the Gcc-bugs
mailing list