This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++14/lambda/impicit-templates] Experimental polymorphic lambda and implicit function template patches
- From: Adam Butcher <adam at jessamine dot co dot uk>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Andrew Sutton <andrew dot n dot sutton at gmail dot com>, Adam Butcher <adam at jessamine dot co dot uk>
- Date: Fri, 19 Jul 2013 10:00:39 +0100
- Subject: Re: [C++14/lambda/impicit-templates] Experimental polymorphic lambda and implicit function template patches
- References: <51DE19EC dot 10300 at redhat dot com>
Hi Jason,
There follows a re-spin of the previous patches. I've addressed your
review comments and cleaned up much of the implementation (including
code location). I've also redesigned the `auto' param handling
(implicit function template generation) to work for plain functions
and member functions as well as lambdas.
This is intended as a step towards implementing the basics of `Terse
Templates' as proposed in section 6.2.1 of N3580. Indeed, if you
consider `auto' to be a concept whose constexpr implementation simply
returns 'true', this is what the current implementation does. I've
Ccd Andrew Sutton for visibility of the work in this area (PATCH 3/3
is the one of interest). I might have a play with this on the
c++-concepts branch if I get time.
As well as the syntax supported by the previous patch-set, this
re-spin also supports the syntax demonstrated by the following
examples for plain functions and member functions:
4. auto plain_fn_or_mem_fn (auto x, auto& y, auto const& z) { return x + y + z; }
5. template <typename Z> auto plain_fn_or_mem_fn (auto x, auto& y, Z const& z) { return x + y + z; }
Currently out-of-line implicit member templates are supported but the
template parameter list must be explicitly specified at the definition
and the return type must be specified. For example:
struct S
{
auto f(auto& a, auto b) { a += b; }
void g(auto& a, auto b);
};
template <typename A, typename B>
void S::g(A& a, B b)
{
a += b;
}
On Wed, 10 Jul 2013 19:35:24 -0700, Jason Merrill wrote:
> On 07/01/2013 04:26 PM, Adam Butcher wrote:
> > Any comments appreciated. Guidance on implementing the conversion
> > operator for stateless generic lambdas would be useful. I've made a
> > few attempts which were lacking!
>
> It seemed to me that N3649's description of the semantics should
> translate pretty easily into an implementation.
>
Indeed. It is quite simple from a spec point of view. And a plain
C++ implementation would be easy. Unfortunately in the compiler I
have not found it as straight-forward.
> What problems are you running into?
>
My previous attempts tried to reuse the existing non-template
conversion-op code with numerous conditional blocks that got out of
hand -- and SEGVd or ICEd to boot. I think it was due to not properly
transforming the type declarators.
Since reworking the implicit function template code I am going to
experiment with a cleaner way. I'll get back to you if I get it done
or if I hit a brick wall!
As always, any feedback appreciated.
Cheers,
Adam
Patch summary (3):
Support template-parameter-list in lambda-declarator.
Avoid crash on symbol table writing when generic lambda declared with
iostream (or potentially other code) included.
Support using `auto' in a function parameter list to introduce an
implicit template parameter.
gcc/cp/cp-tree.h | 11 ++++
gcc/cp/decl.c | 4 +-
gcc/cp/decl2.c | 5 +-
gcc/cp/lambda.c | 9 ++-
gcc/cp/parser.c | 93 +++++++++++++++++++++++++---
gcc/cp/pt.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
gcc/symtab.c | 18 ++++++
7 files changed, 297 insertions(+), 29 deletions(-)
--
1.8.3