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 13:20:25 -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 #8 from redi at gcc dot gnu dot org 2010-06-11 13:20 -------
(In reply to comment #7)
> He is referring to a testcase like:
>
> template<typename T, T C> void f() {
> struct A {
> T x;
> };
>
> T y = 42;
> A a = { y + C };
> }
>
> int main() {
> f<int,1>();
> f<char,1>();
> }
>
> So, we warn for T == char but not for T == int. I know that the standard
Note it's not a warning, it's an error, mandated by the standard.
> considers differently narrowing and overflow but the difference is still
> surprising.
In both cases, T+T has type int, so obviously it fits in an int. It doesn't
necessarily fit in an char, so is an error unless the values are constants and
the actual value can fit in a char.
This is mandated by the standard and the diagnostic is IMHO clear.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44500