constexpr(gcc)错误:在'{'token之前不允许包含括号的初始化程序 [英] Error with constexpr(gcc) - error: a brace-enclosed initializer is not allowed here before '{' token

查看:1506
本文介绍了constexpr(gcc)错误:在'{'token之前不允许包含括号的初始化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct X {
constexpr static char a1[] = "hello"; // Okay
constexpr static const char* a2[] = {"hello"}; // Error
};

int main(){}

使用gcc编译时出现错误:

Compiling with gcc gives the error:


错误:在'{'token

error: a brace-enclosed initializer is not allowed here before '{' token

这是非法使用constexpr吗?

Is this an illegal use of constexpr?

EDIT

我试过3个不同版本的gcc,它编译在最新的4.7.0我有(我只是下载它,我使用mingw-w64),所以它看起来是一个修复的bug

I tried 3 different versions of gcc, and it compiled on the newest 4.7.0 I have (I just downloaded it, I'm using mingw-w64), so it looks to be a fixed bug (a link to the bug would be nice though!).


4.7.0 20120311(prerelease)//好了

4.6.4 20120305(prerelease)//错误

4.7.0 20110829(实验性)//错误

4.7.0 20120311 (prerelease) // Okay
4.6.4 20120305 (prerelease) // Error
4.7.0 20110829 (experimental) // Error


推荐答案

这是一个已修复的错误。我已经确认代码编译与 g ++ 4.7.0 20120311(prerelease)

This is a bug which has been fixed. I have confirmed that the code compiles with g++ 4.7.0 20120311 (prerelease).

这篇关于constexpr(gcc)错误:在'{'token之前不允许包含括号的初始化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆