https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88694
Bug ID: 88694 Summary: constexpr isn't captured correctly in lambda Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: amosbird at gmail dot com Target Milestone: --- Created attachment 45342 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45342&action=edit source code This might be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82643 Tested with: g++ -MMD -MP -DCC_PLAYGROUND -std=c++1z -O2 -v -save-temps -I/home/amos/git/ccutils/ -I/usr/include -I/usr/local/include -c snippet.cpp -o snippet.rel.o Using built-in specs. COLLECT_GCC=g++ Target: x86_64-pc-linux-gnu Configured with: ../configure --disable-multilib --with-system-zlib --enable-languages=c,c++ --enable-gold Thread model: posix gcc version 8.2.0 (GCC) COLLECT_GCC_OPTIONS='-MMD' '-MP' '-D' 'CC_PLAYGROUND' '-std=c++17' '-O2' '-v' '-save-temps' '-I' '/home/amos/git/ccutils/' '-I' '/usr/include' '-I' '/usr/local/include' '-c' '-o' 'snippet.rel.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1plus -E -quiet -v -I /home/amos/git/ccutils/ -I /usr/include -I /usr/local/include -MMD snippet.rel.d -MP -MQ snippet.rel.o -D_GNU_SOURCE -D CC_PLAYGROUND snippet.cpp -mtune=generic -march=x86-64 -std=c++17 -O2 -fpch-preprocess -o snippet.ii ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/include" ignoring duplicate directory "/usr/include" as it is a non-system directory that duplicates a system directory ignoring duplicate directory "/usr/local/include" as it is a non-system directory that duplicates a system directory #include "..." search starts here: #include <...> search starts here: /home/amos/git/ccutils/ /usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../include/c++/8.2.0 /usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../include/c++/8.2.0/x86_64-pc-linux-gnu /usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../include/c++/8.2.0/backward /usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include /usr/local/include /usr/local/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-MMD' '-MP' '-D' 'CC_PLAYGROUND' '-std=c++17' '-O2' '-v' '-save-temps' '-I' '/home/amos/git/ccutils/' '-I' '/usr/include' '-I' '/usr/local/include' '-c' '-o' 'snippet.rel.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1plus -fpreprocessed snippet.ii -quiet -dumpbase snippet.cpp -mtune=generic -march=x86-64 -auxbase-strip snippet.rel.o -O2 -std=c++17 -version -o snippet.s GNU C++17 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 8.2.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++17 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 8.2.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4e924b3bd09bf840dfb30b5ba0fbc5b8 snippet.cpp: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 = std::integral_constant<int, 0>]’: snippet.cpp:8:7: required from ‘constexpr void static_for_impl(Func&&, std::integer_sequence<T, Is ...>) [with T = int; T Begin = 0; Func = main()::<lambda(auto:1)>; T ...Is = {0, 1, 2}]’ snippet.cpp:12:30: required from ‘constexpr void static_for(Func&&) [with T = int; T Begin = 0; T End = 3; Func = main()::<lambda(auto:1)>]’ snippet.cpp:21:26: required from here snippet.cpp:21:49: error: no matching function for call to ‘Foo::print<i>()’ static_for<int, 0, 3>([&](auto i) { [&]() { foo.print<i>(); }(); }); ^~~ snippet.cpp:16:27: note: candidate: ‘template<int x> void Foo::print()’ template <int x> void print() { std::cout << x << std::endl; } ^~~~~ snippet.cpp:16:27: note: template argument deduction/substitution failed: snippet.cpp:21:49: error: ‘this’ is not a constant expression static_for<int, 0, 3>([&](auto i) { [&]() { foo.print<i>(); }(); }); ^~~ snippet.cpp:21:49: note: in template argument for type ‘int’ snippet.cpp: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 = std::integral_constant<int, 1>]’: snippet.cpp:8:7: required from ‘constexpr void static_for_impl(Func&&, std::integer_sequence<T, Is ...>) [with T = int; T Begin = 0; Func = main()::<lambda(auto:1)>; T ...Is = {0, 1, 2}]’ snippet.cpp:12:30: required from ‘constexpr void static_for(Func&&) [with T = int; T Begin = 0; T End = 3; Func = main()::<lambda(auto:1)>]’ snippet.cpp:21:26: required from here snippet.cpp:21:49: error: no matching function for call to ‘Foo::print<i>()’ snippet.cpp:16:27: note: candidate: ‘template<int x> void Foo::print()’ template <int x> void print() { std::cout << x << std::endl; } ^~~~~ snippet.cpp:16:27: note: template argument deduction/substitution failed: snippet.cpp:21:49: error: ‘this’ is not a constant expression static_for<int, 0, 3>([&](auto i) { [&]() { foo.print<i>(); }(); }); ^~~ snippet.cpp:21:49: note: in template argument for type ‘int’ snippet.cpp: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 = std::integral_constant<int, 2>]’: snippet.cpp:8:7: required from ‘constexpr void static_for_impl(Func&&, std::integer_sequence<T, Is ...>) [with T = int; T Begin = 0; Func = main()::<lambda(auto:1)>; T ...Is = {0, 1, 2}]’ snippet.cpp:12:30: required from ‘constexpr void static_for(Func&&) [with T = int; T Begin = 0; T End = 3; Func = main()::<lambda(auto:1)>]’ snippet.cpp:21:26: required from here snippet.cpp:21:49: error: no matching function for call to ‘Foo::print<i>()’ snippet.cpp:16:27: note: candidate: ‘template<int x> void Foo::print()’ template <int x> void print() { std::cout << x << std::endl; } ^~~~~ snippet.cpp:16:27: note: template argument deduction/substitution failed: snippet.cpp:21:49: error: ‘this’ is not a constant expression static_for<int, 0, 3>([&](auto i) { [&]() { foo.print<i>(); }(); }); ^~~ snippet.cpp:21:49: note: in template argument for type ‘int’ make: *** [snippet.rel.o] Error 1