Page 1 of 1

C++11 oddity with -fsingle-precision-constant

Posted: Wed Aug 19, 2015 5:53 pm
by dflogeras
I have a project that I have successfully compiled in the past with ChibiOS-2.6.5 and my (gentoo crossdev) toolchain. It was my testbed for doing STM32 development with modern c++ (-std=c++11). The point here is that I have code, which is in version control that compiled and ran fine as recently as 6 months ago. Now something has changed, which I cannot figure out what, and here is my findings:

If you simple try to compile the following test program:

Code: Select all

#include <algorithm>
int main() {}


and compile with something like:

Code: Select all

armv7m-hardfloat-eabi-g++ -std=c++11 -fsingle-precision-constant test.cpp -c


It even fails if I used a non cross-compiler (ie my amd64 system compiler). It is fine with -std=c++11, or -fsingle-precision-constant separately, but not combined. As far as I can tell, ChibiOS has always (for the extent that I have used it) had -fsingle-precision-constant defined in os/ports/GCC/ARMCMx/rules.mk. However, this seems to be the compiler switch combination that causes the error.

Like I said, my code is under version control. I can rule out that something recent broke it. My cross-compilers are also version controlled (via gentoo's crossdev), I have tried armv7m-hardfloat-eabi 4.7.3, 4.7.4, 4.8.4, 4.9.3, all with the same errors.

What could I be missing, I know this compiled before without any magic. If I remove the -fsingle-precision-constant from the specified rules.mk, it will compile, but I did not do that before. I also don't know what that changes in Chibi if I remove it. Any advice would be appreciated!

Re: C++11 oddity with -fsingle-precision-constant

Posted: Wed Aug 19, 2015 6:31 pm
by Giovanni
No idea, those options are the recommended ones for the M4.

Could you try this compiler?
https://launchpad.net/gcc-arm-embedded

Giovanni

Re: C++11 oddity with -fsingle-precision-constant

Posted: Wed Aug 19, 2015 7:33 pm
by dflogeras
Same problem. I'll put the error listing here, in case it helps someone google it and we find a soln. AFAICT C++11 makes the template deduction more strict, so that min( float, double) is illegal and wont get promoted. So the Line from the gcc random.tcc header

Code: Select all

std::round( std::max( 6.0, std::min( __m, __dx )));


In combination with -fsingle-precision-constants, and -std=c++11, is causing the issue since 6.0 with unspecified type becomes a float, not a double. What I don't get is why this used to compile for me. I've tried the older version of GCC and Chibi that I was using back then.


    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc: In member function 'void std::poisson_distribution<_IntType>::param_type::_M_initialize()':
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)));
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: note: candidates are:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:217:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
    max(const _Tp& __a, const _Tp& __b, _Compare __comp)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
    max(initializer_list<_Tp>);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
    max(initializer_list<_Tp>, _Compare);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1408:55: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc: In member function 'void std::binomial_distribution<_IntType>::param_type::_M_initialize()':
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: error: no matching function for call to 'max(float, const double&)'
    _M_d1 = std::round(std::max(1.0, __d1x));
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: note: candidates are:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:217:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
    _M_d1 = std::round(std::max(1.0, __d1x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
    max(const _Tp& __a, const _Tp& __b, _Compare __comp)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
    _M_d1 = std::round(std::max(1.0, __d1x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
    max(initializer_list<_Tp>);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d1 = std::round(std::max(1.0, __d1x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
    max(initializer_list<_Tp>, _Compare);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1616:42: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d1 = std::round(std::max(1.0, __d1x));
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: error: no matching function for call to 'max(float, const double&)'
    _M_d2 = std::round(std::max(1.0, __d2x));
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: note: candidates are:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/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)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:217:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
    _M_d2 = std::round(std::max(1.0, __d2x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:61:0,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
    max(const _Tp& __a, const _Tp& __b, _Compare __comp)
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algobase.h:261:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
    _M_d2 = std::round(std::max(1.0, __d2x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
    max(initializer_list<_Tp>);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:402:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d2 = std::round(std::max(1.0, __d2x));
    ^
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:60:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
    max(initializer_list<_Tp>, _Compare);
    ^
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/algorithmfwd.h:406:5: note: template argument deduction/substitution failed:
    In file included from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/random:51:0,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/stl_algo.h:66,
    from /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/algorithm:62,
    from tester.cpp:1:
    /home/dave/Desktop/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include/c++/4.9.3/bits/random.tcc:1620:42: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
    _M_d2 = std::round(std::max(1.0, __d2x));

Re: C++11 oddity with -fsingle-precision-constant

Posted: Fri Aug 21, 2015 6:49 pm
by dflogeras