Skip to content

Compiler warning fixes#870

Merged
gittiver merged 2 commits intoCrowCpp:masterfrom
gittiver:compiler_warning_fixes
Jun 26, 2025
Merged

Compiler warning fixes#870
gittiver merged 2 commits intoCrowCpp:masterfrom
gittiver:compiler_warning_fixes

Conversation

@gittiver
Copy link
Copy Markdown
Member

No description provided.

@gittiver gittiver marked this pull request as draft August 18, 2024 16:09
@gittiver gittiver force-pushed the compiler_warning_fixes branch from a573a5c to d68fd26 Compare September 1, 2024 10:00
@gittiver gittiver force-pushed the compiler_warning_fixes branch from d68fd26 to 64f0afb Compare October 21, 2024 22:35
@gittiver gittiver force-pushed the compiler_warning_fixes branch from 64f0afb to 93aae68 Compare November 25, 2024 20:53
@gittiver gittiver self-assigned this Nov 26, 2024
@gittiver gittiver force-pushed the compiler_warning_fixes branch from 93aae68 to c1bae9f Compare February 5, 2025 11:07
@gittiver gittiver linked an issue Feb 27, 2025 that may be closed by this pull request
@gittiver gittiver marked this pull request as ready for review May 17, 2025 11:50
gittiver added 2 commits June 17, 2025 07:35
-removed superfluous semicolon
- added static_cast where it will definitely casue no change in behaviour
- small adaptions in member and parameter types
@gittiver gittiver force-pushed the compiler_warning_fixes branch from c1bae9f to 5bd8fea Compare June 17, 2025 05:42
@gittiver gittiver merged commit 35fd6bd into CrowCpp:master Jun 26, 2025
13 checks passed
Comment thread include/crow/json.h
Comment on lines 854 to 872

inline bool operator==(const rvalue& l, double r)
inline bool operator==(const rvalue& l, const int& r)
{
return l.d() == r;
return l.i() == r;
}

inline bool operator==(double l, const rvalue& r)
inline bool operator==(const int& l, const rvalue& r)
{
return l == r.d();
return l == r.i();
}

inline bool operator!=(const rvalue& l, double r)
inline bool operator!=(const rvalue& l, const int& r)
{
return l.d() != r;
return l.i() != r;
}

inline bool operator!=(double l, const rvalue& r)
inline bool operator!=(const int& l, const rvalue& r)
{
return l != r.d();
return l != r.i();
}
Copy link
Copy Markdown
Contributor

@autoantwort autoantwort Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a compiler warning fix, this is a breaking change of the interface.
Before that change it was possible to compare a rvalue with an double, now it is impossible (it still is possible, but it doesn't do what you expect. Even worse).
And passing a int by const ref also seems... interesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even worse:

    auto data = crow::json::load(R"-({
     "double": 4.5,
})-");
    REQUIRE(data["double"] != 4.7);

Does fail since 4.5 == 4.7 is true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a compiler warning fix, this is a breaking change of the interface. Before that change it was possible to compare a rvalue with an double, now it is impossible (it still is possible, but it doesn't do what you expect. Even worse). And passing a int by const ref also seems... interesting

Direct float comparisons are unsafe, look for the fitting compiler warning. Removal of float comparisons was intentional.

If you want to use it, use the accessor for its floating point value and do it.

Copy link
Copy Markdown
Contributor

@autoantwort autoantwort Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was intentional, please also remove comparison with integers. Otherwise you get unexpected results when comparing with double values.
Also, comparing double is absolutely fine (also see https://stackoverflow.com/a/11422298/10162645).
Also see my example. If i expect a specific floating value in my json I don't want a comparison with some epsilon, I want to check for strict equality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] many conversion warnings at compilation time

3 participants