Bug 78337 - "internal compiler error: Segmentation fault", using local variable in lambda return-type deduction
Summary: "internal compiler error: Segmentation fault", using local variable in lambda...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-13 14:13 UTC by aaron.mcdaid
Modified: 2017-01-25 15:17 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-11-14 00:00:00


Attachments
c++ code (237 bytes, text/plain)
2016-11-13 14:13 UTC, aaron.mcdaid
Details
crashing output from gcc 6.2.0 (829 bytes, text/plain)
2016-11-13 14:14 UTC, aaron.mcdaid
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aaron.mcdaid 2016-11-13 14:13:51 UTC
Created attachment 40032 [details]
c++ code

The following code generates a "internal compiler error: Segmentation fault". Code and gcc trace attached.

If I specify that `f` is `constexpr`, then there is not a segmentation fault. This code began as an attempt to identify at compile time if a given expression can be treated as a constant expression, but here I have simplified it. (The full code worked in clang in the manner that I expected. See http://stackoverflow.com/a/40413051/146041 for more on the context.)

My hunch is that 'f' is the problem here. It is being used in the computation of the return type of the generic lambda. In this particular codebase, I would expect a conventional refusal to compile with an error message about the fact that a constant expression is necessary as the non-type int parameter to the template Void.


//  g++ (GCC) 6.2.0

struct X {
    static constexpr int foo (int b) {
        return b;
    }
};

template<int>
using Void = void;

template<typename F,typename A>
auto
bar(F f, A a) -> decltype( ( f(a) , 0 ) )
{ return {}; }


int main() {
    //constexpr
        int f = 3;
    (void)f;
    auto l = [](auto of_type_X)->
           Void<(decltype(of_type_X)::   foo(f)   ,0)>{return;};
    bar( l , X{});
}
Comment 1 aaron.mcdaid 2016-11-13 14:14:40 UTC
Created attachment 40033 [details]
crashing output from gcc 6.2.0
Comment 2 Jakub Jelinek 2016-11-13 20:56:51 UTC
ICEs since r210017, before it has been rejected.
Comment 3 Jason Merrill 2017-01-11 21:44:13 UTC
Author: jason
Date: Wed Jan 11 21:43:42 2017
New Revision: 244340

URL: https://gcc.gnu.org/viewcvs?rev=244340&root=gcc&view=rev
Log:
	PR c++/78337 - ICE on invalid with generic lambda

	* semantics.c (process_outer_var_ref): Check if containing_function
	is null.  Move inform call under complain test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ice5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
Comment 4 Jakub Jelinek 2017-01-25 15:17:21 UTC
Fixed for 7+.