Topic: this" in trailing-return-type


Author: Jeremiah Willcock <jewillco@osl.iu.edu>
Date: Wed, 15 Dec 2010 19:52:44 CST
Raw View
In a recent snapshot of GCC 4.6, writing a member function such as:

struct foo {
 auto f() -> decltype(this) {return this;}
};

produces the error:

test1.cpp:2:24: error: invalid use of 'this' at top level
test1.cpp:2:24: error: invalid use of 'this' at top level

This issue was also mentioned in a Boost list post at <URL:http://
comments.gmane.org/gmane.comp.lib.boost.devel/209601>, but there did
not appear to be a resolution there.  Is this kind of code allowed by
the standard?  Is its failure in GCC a bug there?

-- Jeremiah Willcock


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Thu, 16 Dec 2010 11:58:58 CST
Raw View
On 2010-12-16 02:52, Jeremiah Willcock wrote:
>
> In a recent snapshot of GCC 4.6, writing a member function such as:
>
> struct foo {
>   auto f() ->  decltype(this) {return this;}
> };
>
> produces the error:
>
> test1.cpp:2:24: error: invalid use of 'this' at top level
> test1.cpp:2:24: error: invalid use of 'this' at top level
>
> This issue was also mentioned in a Boost list post at<URL:http://
> comments.gmane.org/gmane.comp.lib.boost.devel/209601>, but there did
> not appear to be a resolution there.  Is this kind of code allowed by
> the standard?  Is its failure in GCC a bug there?

This is no GCC error, it is currently not allowed by the upcoming
standard draft. See the open issues

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#945
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1207

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]