
2011/7/22 Frédéric Bron <frederic.bron@m4x.org> [...]
I found another issue with g++ (all versions up to 4.6.0) (works fine with msvc 10 and intel 12): although g++ behaves well with fundamental types returned by value, the result of postfix operator++ applied to an int volatile is detected as void! The standard states in 13.6/3 (Built-in operators): "For every pair (T, VQ), where T is an arithmetic type, and VQ is either volatile or empty, there exist candidate operator functions of the form VQ T& operator++(VQ T&); T operator++(VQ T&, int);"
That means that for an "int volatile" variable the corresponding built-in operator should be: int operator++(int volatile &, int); and according to the table above this should be correctly detected as returning non-void. Note that prefix operator++ works fine. This is the program that fails (writes true) with g++ (4.5.2 and 4.6.0):
#include <iostream> #include <iomanip> #include <boost/type_traits/detail/yes_no_type.hpp>
namespace detail {\ struct returns_void_t {}; static ::boost::type_traits::yes_type returns_void(returns_void_t);\ static ::boost::type_traits::no_type returns_void(int);\ } template <typename T> int operator,(const T&, ::detail::returns_void_t); template <typename T> int operator,(const volatile T&, ::detail::returns_void_t);
#define RETURNS_VOID(Expr)\ sizeof(::boost::type_traits::yes_type)\ ==\ sizeof(::detail::returns_void(((Expr), ::detail::returns_void_t())))
int main() { int volatile one_int_volatile; std::cout<<std::boolalpha<<"RETURNS_VOID: "<<(RETURNS_VOID((one_int_volatile++)))<<'\n'; return 0; }
Indeed, this is weird. I would hope that operator--(int volatile&, int) at least returns a consistent result :) At the end of the day, it's sounding like you should just paste a huge warning somewhere in the library concerning volatile-qualified by-value return types. - Jeff