http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46643
Summary: warn_unused_result is not enforced if return type is
templated
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
In the simple test case below, both bar() and baz() should print a warning. In
reality, only baz() prints a warning:
#include <map>
template<typename T>
class foo {
public:
std::pair<T, int> bar() __attribute__((warn_unused_result));
int baz() __attribute__((warn_unused_result));
};
template<typename T> inline
std::pair<T, int> foo<T>::bar() { return std::pair<T, int>(0, 0); }
template<typename T> inline
int foo<T>::baz() { return 0; }
int main(void) {
foo<int> b;
b.bar();
b.baz();
return 0;
}
$ g++ -o a a.cpp
a.cpp: In function 'int main()':
a.cpp:19: warning: ignoring return value of 'int foo<T>::baz() [with T = int]',
declared with attribute warn_unused_result