Boost :: call_traits - Why does gcc give false for this?

Example:

#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

}

Question:

If, I am doing something wrong, I think I should get truefor both, but gcc 4.7.0 outputs falsefor the latter. Is something missing?

+5
source share
1 answer

The nonclass type rvalue is never constant. Only cool r values ​​can be const-qualified.

So, despite the fact that the function is fdeclared as returning const int, and although the type of the function fis equal const int(), the call expression f()is a value of r type (non -const) int.

( ++ 11 f() int. : ++ 11 §3.10/4 , " prvalues ​​ cv- ." )

+8

All Articles