https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68469
Bug ID: 68469 Summary: warn_unused_result attribute ignored for templates return templates Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dushistov at mail dot ru Target Milestone: --- For such code: #include <functional> template<typename T> struct Foo { std::function<T()> f(T p) __attribute__((warn_unused_result)) { return [p]() { return p; }; } }; int main() { Foo<int> foo; foo.f(5); } gcc not produce any warnings, while clang handle this correctly: g++ -std=c++11 -Wunused-result -c test.cpp clang++ -std=c++11 -Wunused-result -c test.cpp -o clang_a.out test.cpp:11:2: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] foo.f(5); ^~~~~ ~ 1 warning generated. return type should depend on template type, like T -> std;:function<T()>, if replace std::function<T()> with not depend on T type, for example with `int`, then warning triggers. I use gcc 5.2