我发现(使用 g++ 6.3)我可以使用该[[deprecated]]
属性来弃用 typedef ( [[deprecated]] typedef longname shortname;
) 但不能使用using
声明 ( [[deprecated]] shortname = longname;
)。
所以我想知道,这是有意的(如果是,为什么?)?或者这是一个错误?
这作为 MWE:
#include <vector>
namespace our {
using vector = std::vector<float>;
}
//[[deprecated("use the namespace 'our'")]] using myvector = std::vector<float>;
[[deprecated("use the namespace 'our'")]] typedef std::vector<float> myvector;
int main() {
myvector a;
return a.size();
}
给出取决于以下警告中注释的行(有意):
g++ -march=native -std=c++11 -m64 -O2 -g -Wextra -Wall -Wshadow -lstdc++ -m64 -g -march=native -flto main.cpp -o main
main.cpp: In function ‘int main()’:
main.cpp:11:12: warning: ‘myvector’ is deprecated: use the namespace 'our' [-Wdeprecated-declarations]
myvector a;
^
main.cpp:8:70: note: declared here
[[deprecated("use the namespace 'our'")]] typedef std::vector<float> myvector;
^~~~~~~~
或以下错误(意外)
g++ -march=native -std=c++11 -m64 -O2 -g -Wextra -Wall -Wshadow -lstdc++ -m64 -g -march=native -flto main.cpp -o main
main.cpp:7:43: error: expected unqualified-id before ‘using’
[[deprecated("use the namespace 'our'")]] using myvector = std::vector<float>;
^~~~~
main.cpp: In function ‘int main()’:
main.cpp:11:3: error: ‘myvector’ was not declared in this scope
myvector a;
^~~~~~~~
main.cpp:12:10: error: ‘a’ was not declared in this scope
return a.size();
^