public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/44500] [C++0x] Bogus narrowing conversion error
Date: Fri, 11 Jun 2010 12:51:00 -0000	[thread overview]
Message-ID: <20100611125128.5673.qmail@sourceware.org> (raw)
In-Reply-To: <bug-44500-11646@http.gcc.gnu.org/bugzilla/>



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


  parent reply	other threads:[~2010-06-11 12:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11 10:46 [Bug c++/44500] New: " gpiez at web dot de
2010-06-11 10:57 ` [Bug c++/44500] [C++0x] " manu at gcc dot gnu dot org
2010-06-11 11:34 ` gpiez at web dot de
2010-06-11 11:38 ` redi at gcc dot gnu dot org
2010-06-11 11:43 ` redi at gcc dot gnu dot org
2010-06-11 12:09 ` gpiez at web dot de
2010-06-11 12:51 ` redi at gcc dot gnu dot org [this message]
2010-06-11 13:07 ` manu at gcc dot gnu dot org
2010-06-11 13:20 ` redi at gcc dot gnu dot org
2010-06-11 13:27 ` gpiez at web dot de
2010-06-11 13:33 ` manu at gcc dot gnu dot org
2010-06-11 14:56 ` redi at gcc dot gnu dot org
2010-06-12  8:46 ` gpiez at web dot de
2010-06-12  8:47 ` gpiez at web dot de
2010-06-13 17:14 ` redi at gcc dot gnu dot org
2010-07-09 21:29 ` jason at gcc dot gnu dot org
2010-07-09 21:29 ` jason at gcc dot gnu dot org
2010-07-09 21:30 ` jason at gcc dot gnu dot org
     [not found] <bug-44500-4@http.gcc.gnu.org/bugzilla/>
2011-03-24  9:32 ` jason at gcc dot gnu.org
2011-03-24  9:37 ` jason at gcc dot gnu.org
2011-03-24 12:04 ` gpiez at web dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100611125128.5673.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).