https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610
Bug ID: 70610 Summary: [6 regression] error: invalid initialization of non-const reference of type Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: david.abdurachmanov at gmail dot com Target Milestone: --- This is a follow up of comment: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21802#c8 Caused by: d175f0193ed47b61eafd213ca2d3dde73f8f5996 is the first bad commit commit d175f0193ed47b61eafd213ca2d3dde73f8f5996 Author: ppalka <ppalka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue Dec 15 03:33:53 2015 +0000 Fix PR c++/21802 (two-stage name lookup fails for operators) Works fine with GCC 5.3.0, Clang 3.7.0 and ICC (16.0.2 20160204). Minimal reproducer by Patrick Palka: struct A { }; A operator+ (A &) { return A (); } A operator+ (const A &) { return A (); } template <typename T> void foo () { +A (); } void bar () { foo<int> (); } $ g++ -c -ansi test.cc test.cc: In instantiation of 'void foo() [with T = int]': test.cc:17:13: required from here test.cc:11:3: error: invalid initialization of non-const reference of type 'A&' from an rvalue of type 'A' +A (); ^~~~~ test.cc:3:3: note: initializing argument 1 of 'A operator+(A&)' A operator+ (A &) { return A (); } ^~~~~~~~ Note, that removing -ansi solves the issue.