This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/55101] New: Invalid implicit conversion in initialization when source type is a template argument type
- From: "cassio.neri at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 27 Oct 2012 17:46:41 +0000
- Subject: [Bug c++/55101] New: Invalid implicit conversion in initialization when source type is a template argument type
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55101
Bug #: 55101
Summary: Invalid implicit conversion in initialization when
source type is a template argument type
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: cassio.neri@gmail.com
Calling f(b) below implies an implicit call to an explicit conversion operator.
This is fine with for gcc 4.8.0 but illegal for clang 3.1 and 3.2 (trunk).
Notice that gcc complains (as it should) in other similar circumstances.
struct A { };
struct B {
explicit operator int() const { return 1; }
explicit operator A() const { return A(); }
};
template <typename T> void f(T b) { int x = b; }
template <typename T> void g(T b) { A y = b; }
int main() {
B b;
//int x = b; // Error: cannot convert 'B' to 'int' in initialization
f(b); // OK for gcc 4.8.0, despite that 'int x = b;' occurs inside f
// Error for clang 3.1 and 3.2.
//A y = b; // Error: conversion from 'B' to non-scalar type 'A' requested
//g(b); // Error: conversion from 'B' to non-scalar type 'A' requested
}