gpt4 book ai didi

c++ - GCC 错误 - 在 constexpr 中输入/递减数组访问

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:12 26 4
gpt4 key购买 nike

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

#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/

我无法在那里创建帐户用户帐户创建已被限制。。我联系了管理员,但对我来说这个错误是严重的。所以它也想通知你。谢谢!

最佳答案

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

关于c++ - GCC 错误 - 在 constexpr 中输入/递减数组访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39427567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com