------- Comment #6 from redi at gcc dot gnu dot org 2010-06-11 12:51 -------
(In reply to comment #5)
> So is it provable that for a "T op T" to be stored in T no narrowing takes
> place?
Yes, if the values are constants.
> If the answer for T == char is no and for T == int it is yes this is rather
> fishy ;-)
That's not what I said. Look:
#include <climits>
struct A {
char x;
};
template<char C, char D> void f() {
A a = { C+D };
}
template<int I, int J> void g() {
A a = { I+J };
}
int main() {
f<1, 1>(); // OK
g<1, 1>(); // OK
f<CHAR_MAX, CHAR_MAX>(); // Error
}
f<1,1>() is ok, because C and D are constants. The type doesn't matter, the
result of C+D is known at compile time and fits in a char.
g<1,1>() is ok, because I and J are constants. The type doesn't matter, the
result of I+J is known at compile time and fits in a char.
f<CHAR_MAX, CHAR_MAX>() is not ok, because the result is known at compile time
and doesn't fit in a char.
See 8.5.4 [dcl.init.list]p6 in teh C++0x draft for the full rules
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44500