public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "maxim.yegorushkin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/64085] New: ICE on C++14 lambda by-reference capture with an initializer
Date: Wed, 26 Nov 2014 16:25:00 -0000	[thread overview]
Message-ID: <bug-64085-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64085

            Bug ID: 64085
           Summary: ICE on C++14 lambda by-reference capture with an
                    initializer
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maxim.yegorushkin at gmail dot com

$ cat test.cc 
    #include <functional>
    #include <iostream>

    template<class T>
    auto make_monad(T&& arg) {
        return [captive = std::forward<T>(arg)](auto&& a) {
            std::cout << __PRETTY_FUNCTION__ << " " << a << '\n';
            return 1;
        };
    }

    template<class T>
    auto make_monad(std::reference_wrapper<T> arg) {
        return [&captive = arg.get()](auto&& a) {
            std::cout << __PRETTY_FUNCTION__ << " " << a << '\n';
            return 1;
        };
    }

    int main() {
        auto monad = [](auto&& captive) {
            return make_monad(std::forward<decltype(captive)>(captive));
        };

        int n = 1;
        monad(1)(1);
        monad(n)(2);
        monad(std::ref(n))(3);
    }

$ /usr/local/ots/7/bin/g++ -v -c -o test.o -pthread -m64 -march=native
-W{all,extra,init-self,cast-align,missing-include-dirs,pointer-arith}
-Werror={return-type,format,format-extra-args,reorder,uninitialized,narrowing}
-Wno-{missing-field-initializers,unused-local-typedefs}
-f{align-functions,diagnostics-show-option,message-length=0} -std=gnu++1y
-Wno-non-virtual-dtor -ftemplate-backtrace-limit=0 -g test.cc
Using built-in specs.
COLLECT_GCC=/usr/local/ots/7/bin/g++49
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.9.2-src/configure --prefix=/usr/local/ots/7
--program-suffix=49 --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --enable-checking=release --disable-multiarch
--disable-multilib --with-gmp-include=/usr/local/ots/7/include
--with-mpfr-include=/usr/local/ots/7/include
--with-mpc-include=/usr/local/ots/7/include
--with-cloog-include=/usr/local/ots/7/include
--with-isl-include=/usr/local/ots/7/include
--with-binutils-include=/usr/local/ots/7/include
--with-gmp-lib=/usr/local/ots/7/lib64 --with-mpfr-lib=/usr/local/ots/7/lib64
--with-mpc-lib=/usr/local/ots/7/lib64 --with-cloog-lib=/usr/local/ots/7/lib64
--with-isl-lib=/usr/local/ots/7/lib64
--with-binutils-lib=/usr/local/ots/7/lib64 --enable-languages=c,c++,fortran,lto
--enable-plugin --enable-initfini-array --enable-gold=default
--enable-libstdcxx-time --enable-linker-build-id --with-linker-hash-style=gnu
--disable-libgcj
Thread model: posix
gcc version 4.9.2 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'test.o' '-pthread' '-m64' '-march=native'
'-Wall' '-Wextra' '-Winit-self' '-Wcast-align' '-Wmissing-include-dirs'
'-Wpointer-arith' '-Werror=return-type' '-Werror=format'
'-Werror=format-extra-args' '-Werror=reorder' '-Werror=uninitialized'
'-Werror=narrowing' '-Wno-missing-field-initializers'
'-Wno-unused-local-typedefs' '-falign-functions' '-fdiagnostics-show-option'
'-fmessage-length=0' '-std=gnu++1y' '-Wno-non-virtual-dtor'
'-ftemplate-backtrace-limit=0' '-g' '-shared-libgcc'
 /home/max/.ots/7/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/cc1plus
-quiet -v -iprefix
/home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/ -D_GNU_SOURCE
-D_REENTRANT test.cc -march=sandybridge -mmmx -mno-3dnow -msse -msse2 -msse3
-mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -maes -mno-sha -mpclmul -mpopcnt
-mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx
-mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c
-mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt
-mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 --param
l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=8192
-mtune=sandybridge -quiet -dumpbase test.cc -m64 -auxbase-strip test.o -g -Wall
-Wextra -Winit-self -Wcast-align -Wmissing-include-dirs -Wpointer-arith
-Werror=return-type -Werror=format -Werror=format-extra-args -Werror=reorder
-Werror=uninitialized -Werror=narrowing -Wno-missing-field-initializers
-Wno-unused-local-typedefs -Wno-non-virtual-dtor -std=gnu++1y -version
-falign-functions -fdiagnostics-show-option -fmessage-length=0
-ftemplate-backtrace-limit=0 -o /tmp/ccljVVdY.s
GNU C++ (GCC) version 4.9.2 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.9.2, GMP version 4.3.2, MPFR version 2.4.2, MPC
version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/include"
ignoring duplicate directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2"
ignoring duplicate directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/x86_64-unknown-linux-gnu"
ignoring duplicate directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/backward"
ignoring duplicate directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include"
ignoring duplicate directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include-fixed"
ignoring nonexistent directory
"/home/max/.ots/7/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2

/home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/x86_64-unknown-linux-gnu

/home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/backward
 /home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include
 /home/max/.ots/7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include-fixed
 /usr/local/include
 /home/max/.ots/7/bin/../lib/gcc/../../include
 /usr/include
End of search list.
GNU C++ (GCC) version 4.9.2 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.9.2, GMP version 4.3.2, MPFR version 2.4.2, MPC
version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4745e1a90ce96a2734afd3f8df070d02
test.cc: In function ‘auto make_monad(std::reference_wrapper<_Tp>)’:
test.cc:14:36: internal compiler error: Segmentation fault
         return [&captive = arg.get()](auto&& a) {
                                    ^
0x98c36f crash_signal
    ../../gcc-4.9.2-src/gcc/toplev.c:337
0x644265 lvalue_kind(tree_node const*)
    ../../gcc-4.9.2-src/gcc/cp/tree.c:236
0x644468 real_lvalue_p(tree_node const*)
    ../../gcc-4.9.2-src/gcc/cp/tree.c:267
0x671672 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
    ../../gcc-4.9.2-src/gcc/cp/lambda.c:497
0x5df75d cp_parser_lambda_introducer
    ../../gcc-4.9.2-src/gcc/cp/parser.c:8999
0x5df75d cp_parser_lambda_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:8721
0x5df75d cp_parser_primary_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:4319
0x5e9a80 cp_parser_postfix_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:5971
0x5ec0f6 cp_parser_unary_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:7172
0x5ecd8f cp_parser_binary_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:7877
0x5ed241 cp_parser_assignment_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:8115
0x5ef32c cp_parser_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:8277
0x600104 cp_parser_expression
    ../../gcc-4.9.2-src/gcc/cp/parser.c:8316
0x600104 cp_parser_jump_statement
    ../../gcc-4.9.2-src/gcc/cp/parser.c:10710
0x600104 cp_parser_statement
    ../../gcc-4.9.2-src/gcc/cp/parser.c:9384
0x600769 cp_parser_statement_seq_opt
    ../../gcc-4.9.2-src/gcc/cp/parser.c:9772
0x6008a6 cp_parser_compound_statement
    ../../gcc-4.9.2-src/gcc/cp/parser.c:9726
0x6009e3 cp_parser_function_body
    ../../gcc-4.9.2-src/gcc/cp/parser.c:18766
0x6009e3 cp_parser_ctor_initializer_opt_and_function_body
    ../../gcc-4.9.2-src/gcc/cp/parser.c:18802
0x6016b2 cp_parser_function_definition_after_declarator
    ../../gcc-4.9.2-src/gcc/cp/parser.c:22927
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
>From gcc-bugs-return-468678-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Nov 26 16:27:30 2014
Return-Path: <gcc-bugs-return-468678-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 25397 invoked by alias); 26 Nov 2014 16:27:30 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 25369 invoked by uid 48); 26 Nov 2014 16:27:25 -0000
From: "maxim.yegorushkin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/64085] ICE on C++14 lambda by-reference capture with an initializer
Date: Wed, 26 Nov 2014 16:27:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: maxim.yegorushkin at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-64085-4-F3RKHYejFS@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64085-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64085-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-11/txt/msg03150.txt.bz2
Content-length: 251

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd085

--- Comment #1 from Maxim Yegorushkin <maxim.yegorushkin at gmail dot com> ---
It compiles fine if I replace the line in question with:

        return [&captive = static_cast<T&>(arg)](auto&& a) {


             reply	other threads:[~2014-11-26 16:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 16:25 maxim.yegorushkin at gmail dot com [this message]
2014-12-08 16:52 ` [Bug c++/64085] " redi at gcc dot gnu.org
2015-03-04 10:23 ` paolo.carlini at oracle dot com
2015-03-04 17:42 ` paolo.carlini at oracle dot com
2015-04-03 17:24 ` paolo.carlini at oracle dot com
2015-04-03 17:24 ` paolo at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-64085-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).