Skip to content

False positive <algorithm> for std::max, std::copy  #908

Closed
@carlosgalvezp

Description

@carlosgalvezp

Hi,

We are consistently getting the following false positive:

c.cpp:10:9: warning: std::max is defined in <algorithm>, which isn't directly #included.

Somehow this failure only happens when importing the nlohmann/json library

The following code reproduces the problem:

#include <vector>

#include <nlohmann/json.hpp>

class Foo
{
 public:
    void bar()
    {
        v.push_back(0.F);  /// < IWYU warning emitted here!?
    }

 private:
    std::vector<float> v;
};

void f()
{
    nlohmann::json json;
    Foo f;
}

This warning goes away if I remove the #include <nlohmann/json.hpp> line. Why is that the case? It doesn't make sense, there's no use of std::max in this .cpp file. There's not even such a use in the json.hpp library itself, which by the way includes the algorithm header.

I have tried increasing verbosity but I can't really understand where the problem comes from. Any ideas? How can I debug further?

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions