https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95773
Bug ID: 95773
Summary: [[nodiscard]] attribute is ignored for calls to
overridden functions
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vladimir.krivopalov at gmail dot com
Target Milestone: ---
The following code compiles fine with GCC 10.1.0 but fails with Clang 10.0.0 :
struct Base {
[[nodiscard]] virtual int f() = 0;
};
struct Derived : Base {
[[nodiscard]] int f() override {
return 1135;
}
};
int main()
{
Derived d;
Base& b = d;
b.f();
return 0;
}
# g++ -Wall -Werror -Wextra -std=c++17 nodiscard.cpp -o nodiscard
# clang++ -Wall -Werror -Wextra -std=c++17 nodiscard.cpp -o nodiscard
nodiscard.cpp:15:5: error: ignoring return value of function declared with
'nodiscard' attribute [-Werror,-Wunused-result]
b.f();
^~~
1 error generated.