GCC 错误 - In/Decrement constexpr 中的数组访问

GCC Bug - In/Decrement array access in constexpr

我在 constexpr 函数中发现了 GCC 6 和 7(不在 GCC 5 中)的错误,如果函数在编译时(错误结果)或运行时(正确结果)求值,这会导致不同的结果。

#include <iostream>

constexpr int bar(int *b) {
  int i = 0;
  b[i++] = 1; // GCC produce here an failure.

  return 0;
}

constexpr int foo()
{
  int tmp[] = {0};
  bar(tmp);

  return tmp[0];
}

constexpr int cexprI = foo();

int main()
{
  std::cout << cexprI << " " << foo() << "\n";

  return 0;
}

Live Example

问题是数组访问内部的递增(递减)操作。

常量表达式的编译时结果为0(错误),运行时结果为1(正确)。

任何人都可以确认此错误并将此报告给:https://gcc.gnu.org/bugzilla/

我无法在那里创建帐户 User account creation has been restricted.。我联系了管理员,但对我来说这个错误是严重的。所以它也想通知你。谢谢!

我打开了 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77553。 感谢您报告问题。