------- 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

Reply via email to