Now that the resolution of issue #1207 (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1207) made it into the standard, the following example (taken from the same page) should compile: struct vector { struct iterator { }; struct const_iterator { }; iterator begin(); const_iterator begin() const; }; class block { vector v; auto end() const -> decltype(v.begin()) { return v.begin(); } }; Currently, GCC gives the same error as before: test.cpp: In member function ‘vector::iterator block::end() const’: test.cpp:9:66: error: could not convert ‘((const block*)this)->block::v.vector::begin()’ to ‘vector::iterator’
I thought there was already a bug report about this but I can't find it, so confirmed
ah I was thinking of PR 45908 (where I provided that reduced testcase - I knew it looked familiar!) but that was for an ICE which is fixed, so this one should be kept for the change in semantics
A simpler test for DR 1207 being implemented is: struct A { auto a() const -> decltype(this) { return this; } }; nc.cc:2:32: error: invalid use of 'this' at top level nc.cc:2:32: error: invalid use of 'this' at top level The late-specified return type should be accepted with the same type as the return statement's expression i.e. const A*
Author: jason Date: Wed Jun 29 21:19:31 2011 New Revision: 175671 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175671 Log: DR 1207 PR c++/49003 * cp-tree.h (struct saved_scope): Add x_current_class_ptr, x_current_class_ref. (current_class_ptr, current_class_ref): Use them. * decl.c (build_this_parm): Handle getting the class type. * parser.c (cp_parser_late_return_type_opt): Set up 'this' for use within the trailing return type. Added: trunk/gcc/testsuite/g++.dg/cpp0x/trailing6.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/decl.c trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/cpp0x/pr45908.C
Implemented for 4.7.
Thanks Jason! Is there any chance of getting this into 4.6.2?
Created attachment 24642 [details] patch for 4.6 I've been pretty free about applying non-regression fix patches to the 4.6 branch, but I think now that 4.6.1 has gone out I'm going to be more conservative. But here's a patch against the 4.6 branch if you want to apply it locally.