简体   繁体   English

C ++ 17中名称空间的属性“不建议使用”

[英]Attribute “deprecated” to namespace in C++17

I have created C++ program to experiment of deprecated keyword of C++17. 我创建了C ++程序来试验C ++ 17 deprecated关键字。

It's working fine in clang(3.8.0) , But, g++(5.4.0) gives an error. 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;

Why? 为什么?

#include <iostream>
using namespace std;

namespace foo  
{ 
  int var; 
}

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

int main() 
{
    bar::var = 10;
    return 0;
}

The clue is in the error message: "expected identifier before [ token". 提示位于错误消息中:“ [标记之前的预期标识符 ”。 The identifier is bar , and it has to appear before [ . 标识符bar ,它必须出现 [ So: 所以:

namespace bar [[deprecated]]
{ } 

Tested with GCC6.3 经过GCC6.3测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c ++ 17 `filesystem` 不是命名空间名称 - c++17 `filesystem` is not a namespace-name 重载命名空间中的运算符和 C++17 中的子命名空间是不明确的 - Overloading an operator in a namespace and a sub-namespace in C++17 is ambiguous C ++ 17,<memory>标准库中不推荐使用的函数? - C++17, deprecated functions in <memory> standard library? C++17 中不推荐使用 `std::result_of` 的原因是什么? - What is the reason for `std::result_of` deprecated in C++17? C ++ 17中不推荐使用std :: is_literal_type - Deprecated std::is_literal_type in C++17 代码片段不能在 C++17 下编译,命名空间问题? - Code snippet doesnot compile under C++17, namespace issue? C ++ 17:编译器对pmr名称空间类的支持 - C++17: compiler support for pmr namespace classes 禁止显示“使用&#39;X&#39;属性是C ++ 17扩展名”警告 - Suppressing “use of the 'X' attribute is a C++17 extension” warnings 为什么`std :: reference_wrapper`在c ++ 17中被弃用,而在c ++ 20中被删除? - Why is `std::reference_wrapper` deprecated in c++17 and removed in c++20? 为什么 rebind <U>::other 在 C++17 中被弃用并在 C++20 中被删除?</u> - Why rebind<U>::other are deprecated in C++17 and removed in C++20?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM