gpt4 book ai didi

c++ - 使用 [[deprecated]] 时会发出 3 次警告

转载 作者:太空狗 更新时间:2023-10-29 21:39:23 26 4
gpt4 key购买 nike

我找到了 this question/answer其中将 [[deprecated]] 的使用描述为 C++14 功能,以指示编译器在使用已弃用函数时发出警告。

我尝试在项目中的一个简单函数中使用它 - 发出了 3 次警告。我最初认为这可能是多个模板实例化,所以我测试了一个简单的程序。

[[deprecated]] void doNothing() {}

int main(){
doNothing();
}

g++ -std=c++14 deprecatedTest.cpp 输出

deprecatedTest.cpp: In function 'int main()':deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]     doNothing();     ^deprecatedTest.cpp:1:21: note: declared here [[deprecated]] void doNothing() {}                     ^deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]     doNothing();     ^deprecatedTest.cpp:1:21: note: declared here [[deprecated]] void doNothing() {}                     ^deprecatedTest.cpp:4:15: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]     doNothing();               ^deprecatedTest.cpp:1:21: note: declared here [[deprecated]] void doNothing() {}

警告应该打印 3 次吗? (为了获得更多关注?)

这似乎是一种奇怪的行为,但我想不出更简单的测试。

最佳答案

这是一个明显的实现质量问题,不太可能是故意的。

如果 GCC Bugzilla 还没有,就在 GCC Bugzilla 上提出吧。

OP has raised this on Bugzilla, as suggested . ☺

关于c++ - 使用 [[deprecated]] 时会发出 3 次警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33117030/

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