嵌套的“ static_for”会导致编译器错误

汤姆

static_for根据这个问题使用我嵌套两个static_for循环,进行编译,g++-7 -std=c++1z main.cpp一切正常

#include <iostream>

template <int First, int Last>
struct static_for
{
  template <typename Lambda>
  static inline constexpr void apply(Lambda const& f)
  {
    if constexpr (First < Last)
      {
    f(std::integral_constant<int, First>{});
    static_for<First + 1, Last>::apply(f);
      }
  }
};

template<int i, int j>
void bar(){
  std::cout << i << " " << j << std::endl;
}

int main(){

  static_for<0,3>
    ::apply([&](auto ii){
          static_for<0,3>
        ::apply([&](auto jj){
              bar<ii.value,jj.value>();
            });
        });

  return 0;
}

但是当我将main功能更改

int main(){

  static_for<0,3>
    ::apply([&](auto ii){
          constexpr int i = ii.value;
          static_for<0,3>
        ::apply([&](auto jj){
              constexpr int j = jj.value;
              bar<i,j>();
            });
        });

  return 0;
}

我收到编译器错误

compiler_error.cpp: In instantiation of ‘main()::<lambda(auto:1)>::<lambda(auto:2)> [with auto:2 = std::integral_constant<int, 0>; auto:1 = std::integral_constant<int, 0>]’:
compiler_error.cpp:11:3:   required from ‘static constexpr void static_for<First, Last>::apply(const Lambda&) [with Lambda = main()::<lambda(auto:1)> [with auto:1 = std::integral_constant<int, 0>]::<lambda(auto:2)>; int First = 0; int Last = 3]’
compiler_error.cpp:28:10:   required from ‘main()::<lambda(auto:1)> [with auto:1 = std::integral_constant<int, 0>]’
compiler_error.cpp:11:3:   required from ‘static constexpr void static_for<First, Last>::apply(const Lambda&) [with Lambda = main()::<lambda(auto:1)>; int First = 0; int Last = 3]’
compiler_error.cpp:32:7:   required from here
compiler_error.cpp:26:29: internal compiler error: in tsubst_copy, at cp/pt.c:14539
        constexpr int i = ii.value;
                          ~~~^~~~~
0x5eb5c2 tsubst_copy
    ../../src/gcc/cp/pt.c:14539
0x5ef666 tsubst_copy
    ../../src/gcc/cp/pt.c:14515
0x5ef666 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:17831
0x5ef549 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:17611
0x5e83c7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:16550
0x5e95f1 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:14477
0x5e95f1 tsubst_init
    ../../src/gcc/cp/pt.c:14483
0x5eb558 tsubst_copy
    ../../src/gcc/cp/pt.c:14681
0x5ef666 tsubst_copy
    ../../src/gcc/cp/pt.c:14515
0x5ef666 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:17831
0x5e83c7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:16550
0x5edd52 tsubst_template_args
    ../../src/gcc/cp/pt.c:11779
0x5eea61 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:16736
0x5ef086 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:17232
0x5e83c7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:16550
0x5e8225 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:15815
0x5e8275 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:15801
0x5e810b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:16027
0x5e810b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
    ../../src/gcc/cp/pt.c:16027
0x5e68a2 instantiate_decl(tree_node*, bool, bool)
    ../../src/gcc/cp/pt.c:22986
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

我的G ++版本

$ g++-7 -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.2.0-1ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04) 

如果确实是编译器错误,我可能应该报告此错误,但是我不知道如何找出该错误是否已报告。我该怎么办?

乔纳斯

这是已被固定在GCC 8(实验)中的错误,这里是所产生的组件的一个例子,只是为了好玩。请注意,由于这不是最终版本,因此不稳定,因此称为“实验性”发行后,可以在此处找到完整的更改列表

因此,请坐下来等待,或者现在在线使用其他编译器,例如clang 4.0.0

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章