https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121368
Bug ID: 121368 Summary: [[nodiscard]] warning not triggered when discarding return value from function pointer call Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: 2023091106 at cauc dot edu.cn Target Milestone: --- g++ -std=c++17 -Wall -Wextra -Wunused -O0 ====code==== #include <functional> struct [[nodiscard]] S {}; S (*test_fun())(); int main(){ test_fun()(); // No warning std::bind(test_fun())(); // Emits warning: discarding nodiscard return return 0; } ====output==== warning: ignoring return value of type 'S' declared with 'nodiscard' attribute [-Wunused-value] Only for the std::bind(test_fun())() line. No warning is emitted for test_fun()();, even though S is [[nodiscard]].