public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57938] New: Compiler breaks when a lambda expression is used as a default parameter in a constructor
@ 2013-07-20  0:49 francesco.nidito at gmail dot com
  2013-07-20  9:07 ` [Bug c++/57938] " francesco.nidito at gmail dot com
  2013-07-22 10:12 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: francesco.nidito at gmail dot com @ 2013-07-20  0:49 UTC (permalink / raw)
  To: gcc-bugs

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

This does not:

template<typename Type>
class Lazy {
...
public:
   explicit Lazy(const std::function<Type*()>&     init,
         const std::function<void(Type*)>& fini
        ):m_object(0),m_initializer(init),m_finalizer(fini) { }
...
};
...
Lazy<Test> 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 heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 875b33a3736d797e27eafd03743d6f46
Lazy.cpp: In constructor 'Lazy<Type>::Lazy(const std::function<Type*()>&, const
std::function<void(Type*)>&) [with Type = Test]':
Lazy.cpp:37:42: internal compiler error: in tsubst_copy, at cp/pt.c:12141
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

C:\test>

To double-check, I tried the same exact code with the VC++ version shipping
with Visual Studio 2012 and it compiles and executes fine.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/57938] Compiler breaks when a lambda expression is used as a default parameter in a constructor
  2013-07-20  0:49 [Bug c++/57938] New: Compiler breaks when a lambda expression is used as a default parameter in a constructor francesco.nidito at gmail dot com
@ 2013-07-20  9:07 ` francesco.nidito at gmail dot com
  2013-07-22 10:12 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: francesco.nidito at gmail dot com @ 2013-07-20  9:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57938

--- Comment #1 from Francesco Nidito <francesco.nidito at gmail dot com> ---
Tried the code on gcc 4.8.1 for win32 (mingw) and it dos not repro.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/57938] Compiler breaks when a lambda expression is used as a default parameter in a constructor
  2013-07-20  0:49 [Bug c++/57938] New: Compiler breaks when a lambda expression is used as a default parameter in a constructor francesco.nidito at gmail dot com
  2013-07-20  9:07 ` [Bug c++/57938] " francesco.nidito at gmail dot com
@ 2013-07-22 10:12 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-22 10:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57938

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.8.0, 4.8.1, 4.9.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
                 CC|francesco.nidito at gmail dot com  |

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Works fine in 4.8.0 too.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-22 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-20  0:49 [Bug c++/57938] New: Compiler breaks when a lambda expression is used as a default parameter in a constructor francesco.nidito at gmail dot com
2013-07-20  9:07 ` [Bug c++/57938] " francesco.nidito at gmail dot com
2013-07-22 10:12 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).