Opened 9 years ago

Closed 9 years ago

#9240 closed Bugs (fixed)

boost 1.54.0 math/constants/constants.hpp doesn't compile with gcc 4.8 with c++11 if you undef __STRICT_ANSI__

Reported by: richardg.work@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

In gcc 4.8, they disabled some numeric literal types for c++11, including the "Q" suffix which is used for float128. Unless you use -fext-numeric-literals, you get a compile error whilst including math/constants/constants.hpp if you compile with -U__STRICT_ANSI__

Change History (5)

comment:1 by John Maddock, 9 years ago

I can reproduce, but don't see any way to fix this - if you undef __STRICT_ANSI__ then you remove all means for us to detect that GCC specific extensions are disabled. Unless you know of another way?

comment:2 by richardg.work@…, 9 years ago

You could use GXX_EXPERIMENTAL_CXX0X, which gcc only defines when you use -std=c++11 (or -std=c++0x)

comment:3 by John Maddock, 9 years ago

You could use GXX_EXPERIMENTAL_CXX0X, which gcc only defines when you use -std=c++11 (or -std=c++0x)

No that doesn't work, __float128 along with 128-bit literals are supported or not as follows:

-std=c++-03   Yes
-std=gnu++-03 Yes
-std=c++-11   No
-std=gnu++-11 Yes

The last two both define __GXX_EXPERIMENTAL_CXX0X__, the only difference between them that I can see from using g++ -E -dM is __STRICT_ANSI__. Indeed, GCC's own headers use __STRICT_ANSI__ to differentiate between these two modes, so I still believe that what you're doing is basically a mistake.

comment:4 by Richard Geary <richardg.work@…>, 9 years ago

There are many reasons for undefining STRICT_ANSI as it's widely used in system headers. If you're using boost in a large legacy codebase, and I expect it's common for people porting large codebases from C++03 to C++11. This bug is really the fault of gcc for overloading the meaning of STRICT_ANSI to imply their special features are enabled/disabled. GCC doesn't own the STRICT_ANSI #define, it's owned by the ISO standard.

Regardless, since the issue is with the numeric literal not the float128 type, is there a different, more compatible way to specify the literals?

comment:5 by John Maddock, 9 years ago

Resolution: fixed
Status: newclosed

Fixed in Git develop: I've added and documented two config macros: BOOST_MATH_USE_FLOAT128 and BOOST_MATH_DISABLE_FLOAT128 which explicitly enable/disable this feature. Defining the latter macro should fix things for your use case.

Note: See TracTickets for help on using tickets.