2012-06-05 3 views
5

예 :boost :: call_traits - 왜 gcc가 false를 제공합니까?

#include <iostream> 
#include <boost/call_traits.hpp> 
#include <type_traits> 

boost::call_traits<int>::param_type f() 
{ 
     return 1; 
} 

int main() 
{ 
     std::cout << std::boolalpha; 
     std::cout << 
     std::is_const<boost::call_traits<int>::param_type>::value 
     << std::endl; // true 
     std::cout << std::is_const<decltype(f())>::value << std::endl; // false 

} 

질문 :

내가 뭔가 잘못하고 있어요 않는 한, 나는 모두 true을 받고해야한다고 생각하지만, GCC 4.7.0 출력 후자 false. 제가 누락 된 것이 있습니까?

답변

8

비 클래스 유형의 rvalue는 절대로 const 한정되지 않습니다. 클래스 유형의 rvalues ​​만 const 한정 될 수 있습니다.

그래서, 함수 fconst int 복귀로 선언 된 경우에도, 그 기능 f의 유형 const int() 있더라도 통화 식 f() 유형 (비 CONST) int의 r- 수치이다.

(. the new C++11 expression category taxonomy에서 호출 식 f()유형 int의 prvalue이다 동일한 규칙이 적용됩니다. "비 클래스 prvalues ​​항상 CV-자격이 유형이"C++ (11) §3.10/4 주 있음)

관련 문제