Simple example showing the problem: struct foo { friend auto test(const foo &) { return 0; } }; g++ rejects this with: test.cc:2:30: error: non-static data member declared ‘auto’ friend auto test(const foo &) { return 0; }
Happens too with GCC 4.9 (20140105), as well as when using decltype(auto).
Maybe Adam can have a look.
Sorry.
I can confirm this bug for GCC 4.9.0 20140604 (prerelease).
Created attachment 34538 [details] ChangeLog entry
Created attachment 34541 [details] Fix: disable the error for friend declarators. The fix is simple. Tested and submitted for approval. (I am a registered contributor.) I don't suppose this warrants a testcase file. If you want to exercise the compiler, here is a more interesting case: template< typename k > struct t { friend auto leak( t ); template< typename v > struct m { friend auto leak( t ) { return v{}; } }; }; int main() { t< int >::m< char > a; decltype( leak( t< int >{} ) ) b; static_assert ( sizeof b == 1, "" ); t< int >::m< short > c; // error: redefinition of ‘auto leak(t<int>)’ }
The following still fails on GCC trunk: struct T { friend auto f() { } }; Sample command line: › ~/code/gcc5/bin/g++ --version g++ (GCC) 5.0.0 20150326 (experimental) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. › ~/code/gcc5/bin/g++ ~/code/hana/test/worksheet.cpp -std=c++1y [...]: error: non-static data member declared ‘auto’ friend auto f() { } ^
(In reply to David Krauss from comment #6) > The fix is simple. Tested and submitted for approval. Thank you. Did you send it to gcc-patches, with jason AT redhat in Cc: ? I can't find any email from you around that date. https://gcc.gnu.org/contribute.html > I don't suppose this warrants a testcase file. Why not? It is the only way to make sure a later refactoring of the code won't regress on this.
I didn't send it to gcc-patches. It's never been necessary for me before. I suppose I can collect the examples here into a testcase file. In the meantime, anyone else is free to take charge and submit it on their own. The change is just a matter of "don't do that."
(In reply to David Krauss from comment #9) > I didn't send it to gcc-patches. It's never been necessary for me before. I appreciate getting direct mail about C++ patches so that I see them faster; I didn't notice this one until today. Also feel free to ping me if I haven't responded after a week. I'll check this in after GCC 5 branches.
Author: jason Date: Tue Apr 14 15:29:27 2015 New Revision: 222095 URL: https://gcc.gnu.org/viewcvs?rev=222095&root=gcc&view=rev Log: PR c++/59766 * decl.c (grokdeclarator): Do not flag friends with deduced return. Added: trunk/gcc/testsuite/g++.dg/cpp1y/auto-fn26.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c
Author: jason Date: Wed Apr 22 20:52:52 2015 New Revision: 222337 URL: https://gcc.gnu.org/viewcvs?rev=222337&root=gcc&view=rev Log: PR c++/59766 * decl.c (grokdeclarator): Do not flag friends with deduced return. Added: branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp1y/auto-fn26.C Modified: branches/gcc-5-branch/gcc/cp/ChangeLog branches/gcc-5-branch/gcc/cp/decl.c
Fixed for 5.2/6.
Author: jason Date: Thu Apr 23 13:21:06 2015 New Revision: 222365 URL: https://gcc.gnu.org/viewcvs?rev=222365&root=gcc&view=rev Log: PR c++/59766 * decl.c (grokdeclarator): Do not flag friends with deduced return. Added: branches/gcc-4_9-branch/gcc/testsuite/g++.dg/cpp1y/auto-fn26.C Modified: branches/gcc-4_9-branch/gcc/cp/ChangeLog branches/gcc-4_9-branch/gcc/cp/decl.c
And 4.9.3.