This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/70737] New: Invalid C++ code compiles when using explicit template conversions
- From: "agriff at tin dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Apr 2016 13:13:08 +0000
- Subject: [Bug c++/70737] New: Invalid C++ code compiles when using explicit template conversions
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70737
Bug ID: 70737
Summary: Invalid C++ code compiles when using explicit template
conversions
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: agriff at tin dot it
Target Milestone: ---
When compiling the code
struct C {
C(){}
template<typename T> explicit operator T () const { return T(42); }
operator int () const { return 1; }
operator double () const { return 3.14; }
};
unsigned foo() {
C x;
unsigned y = x;
return y;
}
g++ compiles giving a warning about using un-initialized variable y in foo on
the return statement.
The code is however invalid because `explicit` rules of the template conversion
and the other two should be considered equivalent and therefore the conversion
required in `foo` is ambiguous.
Note that the generated code after the warning does not use any of the three
conversions and simply returns 0 (code is "xor eax, eax" and "ret").