This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/40283] New: [C++0x] Context-specific explicit conversion doesn't work
- From: "piotr dot wyderski at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 May 2009 13:40:26 -0000
- Subject: [Bug c++/40283] New: [C++0x] Context-specific explicit conversion doesn't work
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
std::unique_ptr has an explicit conversion to
bool operator. However, according to Wikipedia:
http://en.wikipedia.org/wiki/C%2B%2B0x#Explicit_conversion_operators
In C++0x, the explicit keyword can now be applied to conversion operators. As
with constructors, it prevents the use of those conversion functions in
implicit conversions. However, language contexts that specifically require a
boolean value (the conditions of if-statements and loops, as well as operands
to the logical operators) count as explicit conversions and can thus use a bool
conversion operator.
But the following code doen't compile:
#include <stdio.h>
#include <memory>
int main(int argc, char *argv[]) {
std::unique_ptr<int> p(0);
if (p) {}
return 0;
}
Results in:
$ gcc -std=gnu++0x testcase.cpp
testcase.cpp: In function 'int main(int, char**)':
testcase.cpp:10: error: could not convert 'p' to 'bool'
--
Summary: [C++0x] Context-specific explicit conversion doesn't
work
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: piotr dot wyderski at gmail dot com
GCC host triplet: Cygwin/GCC-trunk rev. 147886
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40283