Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of deprecated implicit copy constructor #42

Closed
gnzlbg opened this issue Mar 4, 2015 · 4 comments
Closed

Use of deprecated implicit copy constructor #42

gnzlbg opened this issue Mar 4, 2015 · 4 comments
Assignees

Comments

@gnzlbg
Copy link

gnzlbg commented Mar 4, 2015

Appears when -Wdeprecated is enabled on clang.

src/json.hpp:2076:26: warning: definition of implicit copy constructor for 'iterator' is deprecated because it has a user-declared copy assignment
      operator [-Wdeprecated]
        inline iterator& operator=(const iterator& other) noexcept
                         ^
test/unit.cpp:2471:37: note: implicit copy constructor for 'iterator' first required here
                json::iterator it = j.begin();

In file included from test/unit.cpp:13:
src/json.hpp:2579:32: warning: definition of implicit copy constructor for 'const_iterator' is deprecated because it has a user-declared copy
      assignment operator [-Wdeprecated]
        inline const_iterator& operator=(const const_iterator& other) noexcept
                               ^
test/unit.cpp:2496:38: note: implicit copy constructor for 'const_iterator' first required here
                json::const_iterator it = j_const.begin();
                                     ^

There are also some warnings involving floating point comparisons when Wfloat-equal is enabled:

src/json.hpp:1567:53: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
                    return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
                           ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test/unit.cpp:127:21: note: in instantiation of member function 'nlohmann::operator==' requested here
            CHECK(j == j_reference);
                    ^
test/catch.hpp:8925:44: note: expanded from macro 'CHECK'
#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
                                           ^
test/catch.hpp:1484:39: note: expanded from macro 'INTERNAL_CATCH_TEST'
    } while( Catch::isTrue( false && (expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
                                      ^
In file included from test/unit.cpp:13:
src/json.hpp:1571:53: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
                    return lhs.m_value.number_float == rhs.m_value.number_float;
                           ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~
src/json.hpp:4235:35: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
                    if (float_val == int_val)
                        ~~~~~~~~~ ^  ~~~~~~~
@nlohmann
Copy link
Owner

nlohmann commented Mar 6, 2015

Dear @gnzlbg,

thanks for reporting! It sure looks like a bug. I shall have a look once I'm back from holidays.

All the best
Niels

@nlohmann nlohmann self-assigned this Mar 22, 2015
nlohmann added a commit that referenced this issue Mar 22, 2015
@nlohmann
Copy link
Owner

I currently found no elegant solution to the floating point comparison, and I am not yet sure whether this is an actual issue, because I don't want to do arithmetic inside the JSON values, but only check if two JSON numbers encode the same value... Any comments?

@gnzlbg
Copy link
Author

gnzlbg commented Mar 23, 2015

bool approx(T a , T b) { return !(a > b || a < b); }. By using approx for floating point comparison everywhere we can at least change it easily later if something better comes up.

@nlohmann
Copy link
Owner

Thanks!

GerHobbelt pushed a commit to GerHobbelt/nlohmann-json that referenced this issue May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants