15

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.
Cartesius00
  • 23,584
  • 43
  • 124
  • 195

4 Answers4

22

You can fix it with:

CXXFLAGS+="-D__STRICT_ANSI__"
Leonid Volnitsky
  • 8,854
  • 5
  • 38
  • 53
  • This does not work for me (llvm/clang 3.7.1 with mingw 4.9.3 posix dwarf) – Antonio Apr 11 '16 at 12:56
  • worked 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 – Attila Horváth Jul 12 '17 at 22:57
5

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 :-)

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • 1
    Actually thats not a bad plan a quick -D"__float128=long double" may solve the issues ... – Goz Nov 23 '12 at 09:21
  • This 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. – Nikos C. Nov 23 '12 at 09:24
  • 1
    NO! It does not work due to the template specification redeclaration, but I've found the solution ;-) – Cartesius00 Nov 23 '12 at 09:32
  • But I agree that this is a bug. – Cartesius00 Nov 23 '12 at 09:47
  • 1
    It'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 Nov 23 '12 at 10:38
  • experimentally, 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. – cycollins Jul 23 '19 at 21:39
4

See http://llvm.org/bugs/show_bug.cgi?id=13530#c3 for possible workarounds.

thakis
  • 5,405
  • 1
  • 33
  • 33
2

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.

Cartesius00
  • 23,584
  • 43
  • 124
  • 195
  • Just out of interest, why do you need the `struct`? What's wrong with just `typedef long double __float128;` ? – paxdiablo Nov 23 '12 at 14:10
  • 3
    @paxdiablo There are two template specifications (already), something like: `template <__float128>` and `template `. With typedef you have the conflict. – Cartesius00 Nov 23 '12 at 16:29
  • 9
    I 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. – Alex Bitek Mar 20 '13 at 19:54
  • 2
    I believe it should be `typedef struct { double x, y; } __float128;`, right? Only then will `sizeof(__float128)` evalute to 16 in both GCC and Clang. – Nordlöw May 12 '13 at 13:01
  • With `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. – Hugues Jun 25 '17 at 04:30