https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
Bug ID: 61941 Summary: Mis-parsing of warn_unused_result function with ref-qualifiers Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thiago at kde dot org Testcase: ==== class S { public: S x() const __attribute__ ((__warn_unused_result__)); S y() const & __attribute__ ((__warn_unused_result__)); S y() && __attribute__ ((__warn_unused_result__)); }; ==== (Almost minimal testcase; remove the last __attribute__((__warn_unused_result__)) for truly minimal) When compiled produces the following output: test.ii:7:7: error: ‘S S::y() &&’ cannot be overloaded S y() && __attribute__ ((__warn_unused_result__)); ^ test.ii:6:7: error: with ‘S S::y() const’ S y() const & __attribute__ ((__warn_unused_result__)); ^ Tested with GCC 4.8.1 (openSUSE 13.1) and 4.9.2 (gcc-4_8-branch revision 213070). If you read only the error message, it is correct: "S::y() &&" cannot be overloaded with "S::y() const". However. the overload of y on line 6 that GCC complains about is actually "S::y() const &", which is allowed to be overloaded. Somehow the & ref-qualifier got lost in the parsing. The error does not depend on the order of lines 6 and 7. It does depend on S::x() const appearing before S::y() const & and that both functions have the attribute.