属性";不赞成;在C++;17 < >我已经编写了C++程序,用于对C++ 17的代码< < /Cord>关键字进行实验。p>

属性";不赞成;在C++;17 < >我已经编写了C++程序,用于对C++ 17的代码< < /Cord>关键字进行实验。p>,c++,attributes,c++17,C++,Attributes,C++17,它在clang(3.8.0)中运行良好,但是g++(5.4.0)给出了一个错误 source_file.cpp:9:11: error: expected identifier before ‘[’ token namespace [[ deprecated ]] bar ^ source_file.cpp:9:28: error: ‘bar’ does not name a type namespace [[ deprecated ]] bar

它在clang(3.8.0)中运行良好,但是g++(5.4.0)给出了一个错误

source_file.cpp:9:11: error: expected identifier before ‘[’ token
 namespace [[ deprecated ]] bar
           ^
source_file.cpp:9:28: error: ‘bar’ does not name a type
 namespace [[ deprecated ]] bar
                            ^
source_file.cpp: In function ‘int main()’:
source_file.cpp:16:5: error: ‘bar’ has not been declared
     bar::var = 10;
为什么?

#include <iostream>
using namespace std;

namespace foo  
{ 
  int var; 
}

namespace [[ deprecated ]] bar
{ 
  int var; 
}

int main() 
{
    bar::var = 10;
    return 0;
}
#包括
使用名称空间std;
名称空间foo
{ 
int-var;
}
命名空间[[已弃用]]栏
{ 
int-var;
}
int main()
{
bar::var=10;
返回0;
}

提示出现在错误消息中:“预期标识符位于
[
标记之前”。 标识符是
,它必须出现在之前
[
。因此:

namespace bar [[deprecated]]
{ } 

使用GCC6.3测试时出现了什么错误?您确定5.4已经支持它了吗?根据GCC4.9的规定,从[dcl.attr.deprecated]开始,5.4就已经支持它了。在命名空间上允许使用它:“该属性可以应用于类、typedef名称、变量、非静态数据成员、函数、命名空间、枚举、枚举器或模板专用化的声明。”您需要升级到g++6.1,从8.0开始,它仍然是警告。即使在该属性上,也被直接忽略。我认为您发现了一个bug。