Json: 'Float' number_float_function_t template parameter name conflicts with C '#define Float float'

Created on 4 Oct 2019  路  4Comments  路  Source: nlohmann/json

  • What is the issue you have?
    'Float' number_float_function_t template parameter name conflicts with C #define Float float:
template <typename T, typename Float, typename String>
using number_float_function_t..
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    1) #define Float float
    2) Include json.hpp

  • What is the expected behavior?
    Compilation should succeed as Template parameter shall be unlike standard type names e.g. FloatT instead of Float to prevent collisions.

  • And what is the actual behavior instead?
    Msvc 2017: error C2993: 'float': illegal type for non-type template parameter '__formal'

  • Which compiler and operating system are you using? Is it a supported compiler?
    Msvc 2017

  • Did you use a released version of the library or the version from the develop branch?
    3.7.0

  • If you experience a compilation error: can you compile and run the unit tests?

bug invalid wontfix

Most helpful comment

Can you change the order of the #include lines to put this library first or put an #undef Float before the include of this library?

All 4 comments

Where is this #define coming from? This seems like a dangerous thing to define.

This is from a 3rd-party legacy library sadly. In some cases I have seen a custom 'Float' type in c++ also especially in heavy embedded realm where you need to roll your own soft-implementation but its the nasty #define of C society that hurts here!

Can you change the order of the #include lines to put this library first or put an #undef Float before the include of this library?

Not as easy as just changing the Float to FloatT in the json.h though so I went with this option strangely enough as its 2 characters change to the code fyi :)

Was this page helpful?
0 / 5 - 0 ratings