Bug 54764 - In class initialization of non-static lambda member can't be used in class with default template paramer
Summary: In class initialization of non-static lambda member can't be used in class wi...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks: 54367
  Show dependency treegraph
 
Reported: 2012-10-01 06:43 UTC by Leonid Volnitsky
Modified: 2013-03-23 05:09 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Leonid Volnitsky 2012-10-01 06:43:26 UTC
Clang-3.2 compiles (FWIW), but rejected by GCC 4.7.1 and 4.8:

------------------------------------------------------------------
#include <functional>

template<class T=void>
struct  c{
    std::function<int(int)> f = [](int i){return i+i;};
};

int main() {}
-------------------------------------------------------------------

Error message:

t.cc:6:31: error: default argument for template parameter for class enclosing ‘struct __lambda0’
  function<int(int)> f = [](int i){return i+i;};
                               ^
Comment 1 Daniel Krügler 2012-10-01 11:54:47 UTC
Simplified to get rid of library dependencies:

//-------------------
template<class T = void>
struct c
{
  int (*f)(int) = [](int i){return i + i;};
};
//-------------------
Comment 2 Paolo Carlini 2012-10-01 12:09:09 UTC
lambdas need work
Comment 3 Jason Merrill 2013-03-17 02:39:05 UTC
Author: jason
Date: Sun Mar 17 02:38:50 2013
New Revision: 196742

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196742
Log:
	PR c++/54764
	PR c++/55972
	* name-lookup.h (tag_scope): Add ts_lambda.
	* semantics.c (begin_lambda_type): Use it.
	* decl.c (xref_tag_1): Set CLASSTYPE_LAMBDA_EXPR.
	* pt.c (check_default_tmpl_args): Ignore lambdas.
	(push_template_decl_real): Handle lambdas.
	* tree.c (no_linkage_check): Adjust lambda check.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg4.C
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/name-lookup.h
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/tree.c
Comment 4 Jason Merrill 2013-03-23 05:09:17 UTC
Fixed for 4.8.1.