Bug 54431 - [C++11] g++ crashes when compiling the following file
Summary: [C++11] g++ crashes when compiling the following file
Status: RESOLVED DUPLICATE of bug 53137
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda
: 55156 (view as bug list)
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2012-08-30 23:44 UTC by m101010a
Modified: 2022-03-11 00:32 UTC (History)
1 user (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 m101010a 2012-08-30 23:44:16 UTC
$ cat y.cpp
template <class>
struct foo
{
public:
	void bar()
	{
		[this]{bar();}();
	}
};

int main()
{
	foo<int> ss;
	ss.bar();
}
$ g++ -v -save-temps -std=c++11 y.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7-20120721/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --disable-ppl-version-check --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --enable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release
Thread model: posix
gcc version 4.7.1 20120721 (prerelease) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/cc1plus -E -quiet -v -D_GNU_SOURCE y.cpp -mtune=generic -march=x86-64 -std=c++11 -fpch-preprocess -o y.ii
ignoring nonexistent directory "/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/x86_64-unknown-linux-gnu
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/backward
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include
 /usr/local/include
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/cc1plus -fpreprocessed y.ii -quiet -dumpbase y.cpp -mtune=generic -march=x86-64 -auxbase y -std=c++11 -version -o y.s
GNU C++ (GCC) version 4.7.1 20120721 (prerelease) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.1 20120721 (prerelease), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 4.7.1 20120721 (prerelease) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.1 20120721 (prerelease), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8466381cd327359656bc3ec3a9c33398
y.cpp: In lambda function:
y.cpp:15:1: internal compiler error: in get_expr_operands, at tree-ssa-operands.c:1035
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
$ cat y.ii
# 1 "y.cpp"
# 1 "<command-line>"
# 1 "y.cpp"
template <class>
struct foo
{
public:
 void bar()
 {
  [this]{bar();}();
 }
};

int main()
{
 foo<int> ss;
 ss.bar();
}

Gcc doesn't crash if foo is not a templated class.
Comment 1 m101010a 2012-09-01 22:04:04 UTC
Gcc also doesn't crash if the lambda line is changed to

[this]{this->bar();}();

Although the resulting program does.
Comment 2 Paolo Carlini 2012-10-01 16:37:21 UTC
Confirmed.
Comment 3 Paolo Carlini 2012-10-31 21:53:38 UTC
*** Bug 55156 has been marked as a duplicate of this bug. ***
Comment 4 icegood1980@gmail.com 2012-10-31 22:26:46 UTC
(In reply to comment #1)
> Gcc also doesn't crash if the lambda line is changed to
> 
> [this]{this->bar();}();
> 
> Although the resulting program does.

Of course, resulting program should crash because you have infinite reccursion call. Anyway next code crashes too:
#include <iostream>

template <class>
struct foo
{
public:
 void blah()
 {
  std::cerr<<"blah-blah"<<std::endl;
 }
 void bar()
 {
  [this]{blah();}();
 }
};

int main()
{
 foo<int> ss;
 ss.bar();
}

For workaround with [this] thanks, i should guess...
Comment 5 Markus Trippelsdorf 2012-11-01 07:46:30 UTC
unhandled expression in get_expr_operands():
 <field_decl 0x59f6a18 __this
    type <pointer_type 0x5a01a80
        type <record_type 0x5a017e0 A sizes-gimplified type_5 type_6 QI
            size <integer_cst 0x58acf80 constant 8>
            unit size <integer_cst 0x58acfa0 constant 1>
            align 8 symtab 0 alias set -1 canonical type 0x5a017e0 fields <type_decl 0x5a03450 A> context <translation_unit_decl 0x58c5170 D.1>
            full-name "struct A<int>"
            X() X(constX&) this=(X&) n_parents=0 use_template=1 interface-unknown
            pointer_to_this <pointer_type 0x5a01930> chain <type_decl 0x5a032e0 A>>
        readonly sizes-gimplified unsigned DI
        size <integer_cst 0x58acdc0 constant 64>
        unit size <integer_cst 0x58acde0 constant 8>
        align 64 symtab 0 alias set -1 canonical type 0x5a01a80>
    readonly used unsigned nonlocal decl_7 DI file test.ii line 6 col 6 size <integer_cst 0x58acdc0 64> unit size <integer_cst 0x58acde0 8>
    align 64 offset_align 128
    offset <integer_cst 0x58ace00 type <integer_type 0x58c7000 sizetype> constant 0>
    bit offset <integer_cst 0x58ace80 type <integer_type 0x58c70a8 bitsizetype> constant 0> context <record_type 0x5a01dc8 __lambda0> chain <type_decl 0x5a037e8 __lambda0>>
Comment 6 Markus Trippelsdorf 2012-11-02 11:43:50 UTC
Dup of Bug 53697 and Bug 53137.
Comment 7 Paolo Carlini 2012-11-02 11:52:07 UTC
Dup.

*** This bug has been marked as a duplicate of bug 53137 ***