<algorithm> fails when using -fsingle-precision-constant flag

Asked by Charles Miller

Hello.

When I compile a C++ file that #includes <algorithm> (which I use for std::min() and std::max()), and I use the -fsingle-precision-constant CFLAG, I get lots of errors:

======== start output ==========
Compiling console.cpp:
In file included from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/random:51:0,
                 from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
                 from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/algorithm:62,
                 from ../../../src/conio/console.cpp:30:
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/random.tcc: In member function 'void std::poisson_distribution<_IntType>::param_type::_M_initialize()':
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/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)));
                                                       ^
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: note: candidates are:
In file included from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
                 from ../../../src/conio/console.cpp:30:
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:217:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:217:5: note: template argument deduction/substitution failed:
In file included from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/random:51:0,
                 from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
                 from /opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/algorithm:62,
                 from ../../../src/conio/console.cpp:30:
/opt/launchpad/gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
[etc]
======== end output ==========

When I remove the -fsingle-precision-constant, the errors go away. I presume the arm-none-eabi-g++ is not providing sufficient disambiguation (due to the conflating of floats and doubles) of the floats vs doubles in the template, and hence the errors.

Is this a bug? a feature of the STL that I will have to work around in the make file?
Is there a fix or an adjustment to the compiler that can be made?

Thank you,
Charles Miller

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Charles Miller (millerch1) said :
#1

I should mention my g++ version is:
4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]

Revision history for this message
Andre Vieira (andre-simoesdiasvieira) said :
#2

Hi Charles,

I havent been able to reproduce this with the g++ version provided. Any chance you can provide some minimal sources that cause this to happen?

Also have you tried a newer version of the toolchain?

Cheers,
Andre

Can you help with this problem?

Provide an answer of your own, or ask Charles Miller for more information if necessary.

To post a message you must log in.