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); }
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
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
This is accepted as expected in trunk (it requires C++14 support), I added the testcase.
GCC 6 branch is being closed
Fixed in GCC8.