Bug 47461 - warn_unused_result attribute ignored for templates
Summary: warn_unused_result attribute ignored for templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-25 16:34 UTC by Ian Lance Taylor
Modified: 2015-08-12 14:49 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-01-25 16:53:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2011-01-25 16:34:37 UTC
When I compile this C++ code with current mainline


class C {
 public:
  template<typename T> bool f(T* m) __attribute__((warn_unused_result));
};
template<typename T> inline bool C::f(T* m) { return true; }
void f(C* pc) { int i; pc->f(&i); }

I should see a warning for the call to pc->f.  However, I see no warnings.

I do see a warning for a member function which is not a template.
Comment 1 Jonathan Wakely 2011-01-25 16:53:13 UTC
confirmed. probably related to PR 29823
Comment 2 Jonathan Wakely 2014-05-19 12:07:10 UTC
Works with 4.9.0

w.cc: In function ‘void f(C*)’:
w.cc:6:33: warning: ignoring return value of ‘bool C::f(T*) [with T = int]’, declared with attribute warn_unused_result [-Wunused-result]
 void f(C* pc) { int i; pc->f(&i); }
                                 ^
Comment 3 Paolo Carlini 2015-08-12 14:19:30 UTC
Let's add a testcase and close the bug.
Comment 4 paolo@gcc.gnu.org 2015-08-12 14:48:30 UTC
Author: paolo
Date: Wed Aug 12 14:47:58 2015
New Revision: 226816

URL: https://gcc.gnu.org/viewcvs?rev=226816&root=gcc&view=rev
Log:
2015-08-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/47461
	* g++.dg/warn/Wunused-result-1.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wunused-result-1.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 5 Paolo Carlini 2015-08-12 14:49:02 UTC
Done.