Skip to content

False negative -Wunused-result with libc++ #160051

@chrchr-github

Description

@chrchr-github
#include <vector>

void f(const std::vector<int>& v) {
    v.end() + 1;
}

https://godbolt.org/z/zdvexjY5j
There is no warning with -stdlib=libc++.

With -stdlib=libstdc++:

<source>:4:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
    4 |     v.end() + 1;
      |     ^~~~~~~~~~~
1 warning generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it shouldlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions