[Bug c++/57938] New: Compiler breaks when a lambda expression is used as a default parameter in a constructor

2013-07-19 Thread francesco.nidito at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57938

Bug ID: 57938
   Summary: Compiler breaks when a lambda expression is used as a
default parameter in a constructor
   Product: gcc
   Version: 4.7.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: francesco.nidito at gmail dot com

Created attachment 30530
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30530&action=edit
contains both the .cpp and the .ii files

When specifying a lambda as a default parameter in the constructor of a class,
the compiler breaks with the error "Lazy.cpp:37:42: internal compiler error: in
tsubst_copy, at cp/pt.c:12141"

The error does not appear if I pass the exact same lambda expression explicitly
as a constructor parameter.

This breaks:

template
class Lazy {
...
public:
   explicit Lazy(const std::function& init,
 const std::function& fini = ([](Type *object) -> void {
delete object; })
):m_object(0),m_initializer(init),m_finalizer(fini) { }
...
};
...
Lazy lt([]{ return new Test(42); });
...

This does not:

template
class Lazy {
...
public:
   explicit Lazy(const std::function& init,
 const std::function& fini
):m_object(0),m_initializer(init),m_finalizer(fini) { }
...
};
...
Lazy lt([]{ return new Test(42); },
  [](Type *object) -> void { delete object; });
...

I attached both a minimal .cpp file that produces the error and the .ii file
created by gcc.

This is the full output of the compilation:

C:\test>g++ -v -std=c++11 -save-temps -o Lazy.exe Lazy.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.7.2/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ../src/configure --prefix=/c/temp/gcc/dest
--with-gmp=/c/temp/gcc/gmp --with-mpfr=/c/temp/gcc/mpfr
--with-mpc=/c/temp/gcc/mpc --enable-languages=c,c++ --with-arch=i686
--with-tune=generic --disable-libstdcxx-pch --disable-nls --disable-shared
--disable-sjlj-exceptions --disable-win32-registry --enable-checking=release
--enable-lto
Thread model: win32
gcc version 4.7.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-save-temps' '-o' 'Lazy.exe'
'-mtune=generic' '-march=i686'
 c:/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.7.2/cc1plus.exe -E -quiet -v
-iprefix c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/ Lazy.cpp -mtune=generic
-march=i686 -std=c++11 -fpch-preprocess -o Lazy.ii
ignoring nonexistent directory
"c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/../../../../i686-pc-mingw32/include"
ignoring duplicate directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2"
ignoring duplicate directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2/i686-pc-mingw32"
ignoring duplicate directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2/backward"
ignoring duplicate directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/include"
ignoring nonexistent directory "c:/temp/gcc/dest/include"
ignoring nonexistent directory "/c/temp/gcc/dest/include"
ignoring duplicate directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/include-fixed"
ignoring nonexistent directory
"c:/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.7.2/../../../../i686-pc-mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2

c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2/i686-pc-mingw32

c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include/c++/4.7.2/backward
 c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/include
 c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/../../../../include
 c:\mingw\bin\../lib/gcc/i686-pc-mingw32/4.7.2/include-fixed
End of search list.
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-save-temps' '-o' 'Lazy.exe'
'-mtune=generic' '-march=i686'
 c:/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.7.2/cc1plus.exe -fpreprocessed
Lazy.ii -quiet -dumpbase Lazy.cpp -mtune=generic -march=i686 -auxbase Lazy
-std=c++11 -version -o Lazy.s
GNU C++ (GCC) version 4.7.2 (i686-pc-mingw32)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version
3.1.1-p2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 4.7.2 (i686-pc-mingw32)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version
3.1.1-p2, MPC version 1.0.1
GGC heuri

[Bug c++/57938] Compiler breaks when a lambda expression is used as a default parameter in a constructor

2013-07-20 Thread francesco.nidito at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57938

--- Comment #1 from Francesco Nidito  ---
Tried the code on gcc 4.8.1 for win32 (mingw) and it dos not repro.