https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80543
Bug ID: 80543 Summary: internal compiler error: in tsubst_copy, at cp/pt.c:13039 Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: markku.linnoskivi at iki dot fi Target Milestone: --- Created attachment 41278 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41278&action=edit Example code. It seems that the compiler fails to capture a const local variable. Removing the const from "local" makes the compilation work. This seems to be a regression. Same code compiles on g++-4.9, g++-6.3.0 and g++-7.0.1. (Ubuntu repository versions, not vanilla.) Output: ``` g++-5 -Wall -Wextra -O2 -std=c++14 -o lambda lambda.cpp lambda.cpp: In function ‘auto find(const std::vector<int>&, int)’: lambda.cpp:7:16: warning: variable ‘local’ set but not used [-Wunused-but-set-variable] const auto local = val; ^ lambda.cpp: In instantiation of ‘find(const std::vector<int>&, int)::<lambda(const auto:1&)> [with auto:1 = int]’: /usr/include/c++/5/bits/predefined_ops.h:234:30: required from ‘bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Predicate = find(const std::vector<int>&, int)::<lambda(const auto:1&)>]’ /usr/include/c++/5/bits/stl_algo.h:120:14: required from ‘_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<find(const std::vector<int>&, int)::<lambda(const auto:1&)> >]’ /usr/include/c++/5/bits/stl_algo.h:161:23: required from ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<find(const std::vector<int>&, int)::<lambda(const auto:1&)> >]’ /usr/include/c++/5/bits/stl_algo.h:3815:28: required from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Predicate = find(const std::vector<int>&, int)::<lambda(const auto:1&)>]’ lambda.cpp:13:26: required from here lambda.cpp:12:38: internal compiler error: in tsubst_copy, at cp/pt.c:13039 return i == local; ```