我在Clang中发现了一个错误? [英] Have I found a bug in Clang?

查看:227
本文介绍了我在Clang中发现了一个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Clang

class Prasoon{

  static const int dummy = 0;

};
int const Prasoon::dummy = 0;

int main(){}

编译时使用 Clang时出现错误。

prasoon@prasoon-desktop ~ $ clang++ --version
clang version 2.8 (trunk 107611)
Target: i386-pc-linux-gnu
Thread model: posix
prasoon@prasoon-desktop ~ $ cat bug.cpp
class Prasoon{

      private:
      static const int dummy = 0;

    };

int const Prasoon::dummy = 0;

int main(){}
prasoon@prasoon-desktop ~ $ clang++ bug.cpp
prasoon@prasoon-desktop ~ $ 

但是当我使用 g ++ 编译同样的代码时,

But when I compiled the same code with g++ I got an error as expected.

prasoon@prasoon-desktop ~ $ g++ bug.cpp
bug.cpp:8: error: duplicate initialization of ‘Prasoon::dummy’

所以我发现了一个错误 Clang

So have I found a bug in Clang?

推荐答案

是的,您发现了一个错误。

Yes, you have found a bug.

在标准中表示:


9.4.2-3:
如果静态数据成员是const
字面类型,它在
类定义中的声明可以指定
brace-or- equal-initializer其中
每个initializer-clause是
赋值表达式的一个常量
表达式。
文本类型的静态数据成员可以在
类定义中使用constexpr
说明符声明;如果是,它的声明
应指定一个
括号或等于初始化器,其中
每个initializer子句是一个
赋值表达式是一个常量
表达。 [注:在这两个
的情况下,成员可能出现在
常量表达式中。 - end note]
成员仍然在
命名空间范围中定义,如果它在
程序和命名空间范围中使用
定义不包含
initializer。

这篇关于我在Clang中发现了一个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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