http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49812
Summary: strange return type for built-in operator++(int, int) Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: frederic.b...@m4x.org The following code attempts to detect if operator++ returns void or not. The program writes true (meaning that operator++ returns void) instead of false. msvc 10 and icpc 12.0 are right in writing false. 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); which should bind well with operator,(const int&, returns_void_t). #include <iostream> #include <iomanip> namespace detail { typedef char yes_type; struct no_type { char padding[8]; }; struct returns_void_t {}; static yes_type returns_void(returns_void_t); static 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(::detail::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; }