3

我想让这个代码工作

#include <cstddef>

template <bool B, auto T, auto F>
struct conditional { static constexpr auto value = T; };

template <auto T, auto F>
struct conditional<false, T, F> { static constexpr auto value = F; };

template <std::size_t N, auto... Dims>
struct static_extent;

template <std::size_t N>
struct static_extent<N> {
   static constexpr std::size_t value = 0;
};

template <std::size_t N, auto Dim, auto... Dims>
struct static_extent<N, Dim, Dims...> {
  static constexpr auto value =
     conditional<
        (N == 0),
        Dim,
        static_extent<N-1, Dims...>::value
     >::value;
};

enum class dynamic_extent_tag {};
inline constexpr dynamic_extent_tag dyn{-1};

int main()
{
    static_assert(static_extent<1, 33, dyn, 19>::value == dyn, "");
    static_assert(static_extent<0, 33, dyn, 19>::value == 33, "");
}

我已经在Godbolt上对其进行了测试,它似乎可以与 clang 一起使用。不幸的是,我被绑定到 gcc,它给了我一个 ICE 和一个堆栈跟踪。我试图在他们的bugzilla上冲浪,但我有点迷路了。

是否值得为主干版本提交错误报告?它甚至想要吗?有人知道这是否已经是一个已知问题吗?我寻找关键字“冰”,但在那里找不到任何有用的东西。

4

2 回答 2

1

是的,应该报告所有 ICE。

我已经为你打开了https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79556

谢谢。

于 2017-02-16T14:59:23.793 回答
0

我想为所有找到您问题的读者回答:

  • 是的,非常感谢您为中继提交错误报告。在开发阶段,与发布后相比,修复错误要容易得多。
  • 是的,它是想要的。如果 bug 或回归是在几天或几周前引入的,那么更改仍然存在并且不太难以修复。

你应该如何进行?

  • 尝试使用最新版本的主干或尽可能新的版本。
  • 重新编译您的代码并添加-save-temps. 这将生成一个 .i(对于 C,它将是 .ii 对于 C++)文件。
  • 使用与上述相同的标志进行编译,但使用 .i/.ii 文件检查问题是否仍然存在。
  • 在 gcc.gnu.org/bugzilla/ 上发布错误,包括错误消息、GCC 版本 ( gcc - v),并附上您的 .i/-ii 文件。

顺便说一句,LLVM/Clang 的工作方式类似:https ://releases.llvm.org/1.9/docs/HowToSubmitABug.html

进一步阅读:

于 2020-11-30T19:14:50.990 回答