-fsingle-precision-constant breaks STL

Bug #1452470 reported by Marc Singer
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Fix Released
Undecided
Unassigned

Bug Description

The upgrade to gcc-arm-none-eabi-4_9-2015q1 has changed the way that a portion of the STL compiles s.t. the -fsingle-precision-constant switch breaks compilation.

The attached file includes a compiler command line. When compiled with the 2015q1 compiler, an error is generated that includes this:

/opt/gcc-arm-none-eabi-4_9-2015q1/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: error: no matching function for call to 'max(float, const double&)'
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));

The 2014q4 compiler builds the source file without errors.

Revision history for this message
Marc Singer (eleventen) wrote :
Revision history for this message
Tony Liu (mrtoniliu) wrote :

Hi,

The compiler actually did right thing. Two parameters of std::max() should be the same type. There are no definition of std::max() can take one float and one double.

This case is probably caused by the header file changes. The difference between 2014q4 and 2015q1 is that during pre-processing 2015q1 calls std::max() but 2014q4 didn't.

Regards,
Tony

Revision history for this message
strongly-typed (stronglytyp3d) wrote :

Hi,

the compiler fails with an empty main function as soon as <algorithm> is included and -fsingle-precision-constant is set.

Regards,

Revision history for this message
strongly-typed (stronglytyp3d) wrote :
Revision history for this message
strongly-typed (stronglytyp3d) wrote :
Revision history for this message
Andre Vieira (andre-simoesdiasvieira) wrote :

Hi,

As explained by Tony before, this bug is due to the STL *header* containing:

std::max (1.0, __d1x)

__d1x is a double and 1.0 is a float because of -fsingle-precision-constant. However, std::max is only defined for (float, float) or (double, double). This code is guarded by the _GLIBCXX_USE_C99_MATH_TR1 macro which was not set in our 4.8 based toolchain releases. This explains why it fails with only an include, why only since the 4.9 releases and why with -fsingle-precision-constant. STL developers might be convinced to add a (double) cast in front of the few constants there but they might as well refuse given that -fsingle-precision is not standard compliant [1]. Prefixing the 3 constants in arm-none-eabi/include/c++/4.9.3/bits/random.tcc with (double) fixes the issue.

[1] section 6.4.4.2 paragraph 4 of C11 (and similar text exist in earlier versions) explicitly states that unsuffixed floating constant have double precision.

Kind Regards,

Revision history for this message
Xo Wang (xo) wrote :
Changed in gcc-arm-embedded:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.