clang and __float128 bug/error
Solution 1
You can fix it with:
CXXFLAGS+="-D__STRICT_ANSI__"
Solution 2
I don't think clang
supports __float128
. It may be the same type as long double
(which is 16 bytes in clang
) so it may be a simple case of inserting:
#define __float128 long double
or:
typedef long double __float128;
somewhere early in your include chain.
I'm not guaranteeing that will work but it may, and it's probably best to try it out rather than wait until clang
starts supporting more gcc
extensions.
Either that, or switch to gcc
, if that's an option. I'm pretty certain that gcc
supports all of the gcc
extensions :-)
Solution 3
See http://llvm.org/bugs/show_bug.cgi?id=13530#c3 for possible workarounds.
Solution 4
The solution is to have this declaration. It works like a charm:
#ifdef __clang__
typedef struct { long double x, y; } __float128;
#endif
Solutions with #define
don't work because of the template specification redeclaration error.
Of course this is a hack, and you must be safe. I want clang just for a few experiments, so it won't cause any troubles.
Comments
-
Cartesius00 about 2 years
I've successfully compiled the current 3.3 branch of clang. But then C++ compilation of any file fails with the bug/error. Can that be fixed?
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/iostream:39: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/ostream:39: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/ios:40: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/char_traits.h:40: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_algobase.h:65: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_pair.h:61: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/move.h:57: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/type_traits:256:39: error: use of undeclared identifier '__float128' struct __is_floating_point_helper<__float128> ^ 1 error generated.
-
Goz over 11 yearsActually thats not a bad plan a quick -D"__float128=long double" may solve the issues ...
-
Nikos C. over 11 yearsThis is probably a bug in clang. Not surprising, since 3.3 is the current development branch and 3.2 hasn't even been released yet. The OP is pretty much using experimental code. Clang is supposed to work with GCC's C++ library.
-
Cartesius00 over 11 yearsNO! It does not work due to the template specification redeclaration, but I've found the solution ;-)
-
Cartesius00 over 11 yearsBut I agree that this is a bug.
-
paxdiablo over 11 yearsIt's only a bug if clang states they support it. Otherwise it's just a difference in implementation - there's no mandated support for that type in ISO C.
-
paxdiablo over 11 yearsJust out of interest, why do you need the
struct
? What's wrong with justtypedef long double __float128;
? -
Cartesius00 over 11 years@paxdiablo There are two template specifications (already), something like:
template <__float128>
andtemplate <long double>
. With typedef you have the conflict. -
Alex Bitek over 11 yearsI had the same problem because I compiled my code with Clang 3.2 and -std=gnu++11. After I changed to -std=c++11 it fixed the problem.
-
Nordlöw about 11 yearsI believe it should be
typedef struct { double x, y; } __float128;
, right? Only then willsizeof(__float128)
evalute to 16 in both GCC and Clang. -
Kolyunya over 10 years@9emE0iL18gxCqLT thanks! That worked like a miracle!
-
Antonio about 8 yearsThis does not work for me (llvm/clang 3.7.1 with mingw 4.9.3 posix dwarf)
-
Hugues about 7 yearsWith
Cygwin
and clang version 3.9.1, the above solution no longer worked because__float128
is somehow already defined but disabled. However, combining the above solution with-D__float128=dummy_name_float128
did work. -
Attila Horváth almost 7 yearsworked for me, adding set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STRICT_ANSI__") after project definition to CmakeLists.txt. I'm using llvm/clang 4.0.1 with mingw 7.1 x86_64 posix seh
-
cycollins almost 5 yearsexperimentally, as of this writing clang 10 implements long double as IEEE extended 80-bit float. They make no claims and they don't support the gcc command line option to enable 128-bit long longs. It would be nice though.