Skip to content

[clang] [[nodiscard]] ignored in std::function due to warning suppression in system headers #141791

Open
@avikivity

Description

@avikivity

Consider:

#include <functional>

struct [[nodiscard]] A {};

A f();

std::function<void ()> ff(f);

void g() {
    ff();
}

std::function calls f() (or rather, a function pointer that that returns an A), but returns void. So somewhere, something should complain about the nodiscard A being discarded. But it looks like it's explicitly silenced somewhere, causing hard-to-find bugs.

Investigation by the gcc team [1] revealed it's likely due to -Wunused-result being suppressed in system headers, which it probably should not be.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120460

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"libstdc++GNU libstdc++ C++ standard library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions