is deprecated in C++98/C++03, and has been removed (that is, §4.2/2 removed) in C++0x.
So, the code is not valid in C++0x.
However, MinGW g++ 4.4.1 still only emits a warning, not error.
C++98/C++03 §4.2/2 (which is removed in C++0x):
A string literal (2.13.4) that is not a wide string literal can be converted to an rvalue of type “pointer to char”; a wide string literal can be converted to an rvalue of type “pointer to wchar_t”. In either case, the result is a pointer to the first element of the array. This conversion is considered only when there is an explicit appropriate pointer target type, and not when there is a general need to convert from an lvalue to an rvalue. [Note: this conversion is deprecated. See Annex D. ] For the purpose of ranking in overload resolution (13.3.3.1.1), this conversion is considered an array-to-pointer conversion followed by a qualification conversion (4.4). [Example: "abc" is converted to “pointer to const char” as an array-to-pointer conversion, and then to “pointer to char” as a qualification conversion. ]
I believe that this is now illegal in C++0x. C++03 had a special caveat for this conversion for legacy code, but C++0x removed it and now you are violating const correctness.
Of course, I don't know if any real compilers have removed it, but they would be well within their rights.
发布评论
评论(2)
该转换
在 C++98/C++03 中已弃用,并已在 C++0x 中删除(即删除了 §4.2/2)。
因此,该代码在 C++0x 中无效。
但是,MinGW g++ 4.4.1 仍然只发出警告,而不发出错误。
The conversion
is deprecated in C++98/C++03, and has been removed (that is, §4.2/2 removed) in C++0x.
So, the code is not valid in C++0x.
However, MinGW g++ 4.4.1 still only emits a warning, not error.
我相信这在 C++0x 中现在是非法的。 C++03 对遗留代码的这种转换有一个特殊的警告,但 C++0x 删除了它,现在你违反了 const 正确性。
当然,我不知道是否有真正的编译器删除了它,但他们完全有权利这样做。
I believe that this is now illegal in C++0x. C++03 had a special caveat for this conversion for legacy code, but C++0x removed it and now you are violating const correctness.
Of course, I don't know if any real compilers have removed it, but they would be well within their rights.