This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/44500] [C++0x] Bogus narrowing conversion error
- From: "redi at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Jun 2010 11:42:50 -0000
- Subject: [Bug c++/44500] [C++0x] Bogus narrowing conversion error
- References: <bug-44500-11646@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from redi at gcc dot gnu dot org 2010-06-11 11:42 -------
(In reply to comment #2)
> Sorry for the unicode mess. The error> I believe I should not get an error, even if the template parameter type is
> larger than a char, as long as the template parameter value fits in in char, so
>
> template<int C> void f() {
> char y = 42;
> A a = { y+C };
> }
>
> should give no error, as long as C fits in a char. IMHO ;-)
Just to be extra clear: C is a constant and the narrowing is *not* due to C,
consider:
struct A {
char x;
};
template<int C> void f() {
A a = { C };
}
int main() {
f<1>();
}
Here C is an int, but it's a constant and it is provable that no narrowing
takes palce.
The problem in your example is 'y' not 'C' because the value of 'y' is not a
constant.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44500