开发者

How is decltype supposed to work with operator,

开发者 https://www.devze.com 2023-02-07 16:16 出处:网络
decltype is supposed to yield the type of its parameter. A comma expression is supposed to have the type of its right hand operand. In the example below all but c2 are false when compiled with VS2010.

decltype is supposed to yield the type of its parameter. A comma expression is supposed to have the type of its right hand operand. In the example below all but c2 are false when compiled with VS2010. When it comes to c1 this is weird to me but clearly standard compliant, while for c4 and c5 I'm not sure... is this correct, or is it a compiler bug? Sadly enough, my real code relied on is_reference to return true in at least for c4.

Two last lines of function compiles as expected which shows that the actual evaluation of the comma expression works.

#include <type_traits>

void comma()
{
 int str = 1;

 bool c1 = std::is_reference<decltype(str)>::value;
 bool c2 = std::is_reference<decltype((str))>::value;
 bool c3 = std::is_reference<decltype((str, str))>::value;
 bool c4 = std::is_reference<decltype((str, str))>::value;
 bool c5 = std::is_reference<decltype((str, (str)))&g开发者_JS百科t;::value;

 int& s2 = (1, str);
 s2 = 2;
}


As far as I can see, you are correct that decltype((str, str)) and decltype((str, (str))) should both denote int& as an expression that has a comma operator should have the same value and value category as the second operand and str is an lvalue.

I think that it's a bug in C++0x support in VS2010.

0

精彩评论

暂无评论...
验证码 换一张
取 消