http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55386
Bug #: 55386
Summary: operator void called for class objects converted to
void type.
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
C++11 12.3.2/1 says that:
A conversion function is never used to convert a (possibly cv-qualified) object
to the (possibly cv-qualified) same object type (or a reference to it), to a
(possibly cv-qualified) base class of that type (or a reference to
it), or to (possibly cv-qualified) void.
The standard also puts a note at the end of same page which reads:
A conversion to void does not invoke any conversion function (5.2.9).
But the following program shows that g++ calls operator void for class objects
converted to the void type.
--------------------- BEGIN ---------------------
#include <iostream>
struct test
{
operator void () const { std::cout << "test::operator void ()" << std::endl; }
};
int main ()
{
test const t;
(void)t; // calls test::operator void
return 0;
}
--------------------- END ---------------------
My command line:~/gcc/4.7.0/bin/c++ -std=c++11 -Wall -Wextra t.cc
My compiler version:~/gcc/4.7.0/bin/c++ -v
Reading specs from /home/meng/gcc/4.7.0/lib/gcc/i686-pc-linux-gnu/4.7.0/specs
COLLECT_GCC=/home/meng/gcc/4.7.0/bin/c++
COLLECT_LTO_WRAPPER=/home/meng/gcc/4.7.0/libexec/gcc/i686-pc-linux-gnu/4.7.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/home/meng/gcc/4.7.0/
--enable-languages=c,c++
Thread model: posix
gcc version 4.7.0 (GCC)