Bug 66177 - warn_unused_result doesn't work for non-PODs
Summary: warn_unused_result doesn't work for non-PODs
Status: RESOLVED DUPLICATE of bug 38172
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 70365 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-05-16 15:00 UTC by Sergio Martins
Modified: 2016-04-28 16:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergio Martins 2015-05-16 15:00:45 UTC
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.
Comment 1 Sergio Martins 2015-05-16 15:23:38 UTC
It this is known, at least please mention in the documentation it only works for built-in types.
Comment 2 Andrew Pinski 2016-03-22 20:59:41 UTC
*** Bug 70365 has been marked as a duplicate of this bug. ***
Comment 3 Jason Merrill 2016-04-28 16:01:49 UTC
Dup.

*** This bug has been marked as a duplicate of bug 38172 ***