https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66177
Bug ID: 66177 Summary: warn_unused_result doesn't always work Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at bobbyperu dot info Target Milestone: --- Testcase fails to work with gcc, works with clang. ===== struct QSize { QSize(int w, int h) : wd(w), ht(h) {} QSize expandedTo() const __attribute__ ((__warn_unused_result__)) { return QSize(2, 3); } private: int wd; int ht; }; void foo() { QSize sz(2, 2); sz.expandedTo(); } ===== $ g++ testcase.cpp -c -Wunused-result $ clang++ testcase.cpp -c -Wunused-result testcase.cpp:18:5: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] sz.expandedTo(); ^~~~~~~~~~~~~ 1 warning generated.