Bug 78006 - [7 Regression] Segmentation fault with 'using' and generic lambda trailing return types
Summary: [7 Regression] Segmentation fault with 'using' and generic lambda trailing re...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P4 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, error-recovery, ice-on-invalid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-10-17 10:52 UTC by Vittorio Romeo
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.3.0, 8.0
Known to fail: 5.4.0, 6.2.0, 7.0, 7.5.0
Last reconfirmed: 2016-10-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vittorio Romeo 2016-10-17 10:52:28 UTC
The following code snippet causes a segmentation fault on (at least) g++ 7 and g++ 6.1:
(On Godbolt: https://godbolt.org/g/yOCXlG)

#include <type_traits>

template <typename... TFs>
auto x(TFs&&... fs)
{
    using rt = std::common_type_t<decltype(fs(0))...>;    

    // internal compiler error: Segmentation fault    
    return [](auto) -> rt { };    
}

int main()
{
    // required from here
    x([](int){})(0);    
}



---------------------



Note that getting rid of the 'using' prevents the segfault:
(On Godbolt: https://godbolt.org/g/Hoxst0)

#include <type_traits>

template <typename... TFs>
auto x(TFs&&... fs)
{    
    return [](auto) -> std::common_type_t<decltype(fs(0))...> { };
}

int main()
{
    x([](int){})(0);    
}
Comment 1 Martin Liška 2016-10-17 12:29:56 UTC
Confirmed, started with r231713.

Error message with GCC 5.3.0:

pr78006.cpp: In substitution of ‘template<class auto:1> x(TFs&& ...)::<lambda(auto:1)> [with auto:1 = int]’:
pr78006.cpp:15:19:   required from here
pr78006.cpp:9:24: error: expansion pattern ‘void’ contains no argument packs
     return [](auto) -> rt { };    
                        ^
pr78006.cpp: In function ‘int main()’:
pr78006.cpp:15:19: error: no match for call to ‘(x(TFs&& ...) [with TFs = {main()::<lambda(int)>}]::<lambda(auto:1)>) (int)’
     x([](int){})(0);    
                   ^
pr78006.cpp:15:19: note: candidate: rt (*)(auto:1) <conversion>
pr78006.cpp:15:19: note:   candidate expects 2 arguments, 2 provided
pr78006.cpp:9:24: note: candidate: template<class auto:1> x(TFs&& ...)::<lambda(auto:1)> [with auto:1 = auto:1; TFs = {main()::<lambda(int)>}]
     return [](auto) -> rt { };    
                        ^
pr78006.cpp:9:24: note:   substitution of deduced template arguments resulted in errors seen above
Comment 2 paolo@gcc.gnu.org 2017-10-10 20:46:58 UTC
Author: paolo
Date: Tue Oct 10 20:46:26 2017
New Revision: 253621

URL: https://gcc.gnu.org/viewcvs?rev=253621&root=gcc&view=rev
Log:
2017-10-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/78006
	* g++.dg/cpp1y/auto-fn40.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/auto-fn40.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 3 Paolo Carlini 2017-10-10 20:49:39 UTC
This is accepted as expected in trunk (it requires C++14 support), I added the testcase.
Comment 4 Jakub Jelinek 2018-10-26 10:19:10 UTC
GCC 6 branch is being closed
Comment 5 Richard Biener 2019-11-14 09:33:00 UTC
Fixed in GCC8.