public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Eric Blake <ebb9@email.byu.edu> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: c++/1920 Date: Sun, 01 Apr 2001 00:00:00 -0000 [thread overview] Message-ID: <20010209225600.10926.qmail@sourceware.cygnus.com> (raw) The following reply was made to PR c++/1920; it has been noted by GNATS. From: Eric Blake <ebb9@email.byu.edu> To: mdejong@redhat.com, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: c++/1920 Date: Fri, 09 Feb 2001 15:51:35 -0700 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=1920&database=gcc Actually, it looks like this bug should be recategorized as accepts-illegal. Consider this variation: #include <stdio.h> void foo(unsigned &bar) { bar = 1; } int main() { unsigned a = 0; foo((unsigned) a); if (a == 1) printf("OK\n"); else { printf("a = %d, expeceted 1", a); return 1; } return 0; } $ g++ -o foo foo.cc foo.cc: In function `int main()': foo.cc:9: initialization of non-const reference type `unsigned int &' foo.cc:9: from rvalue of type `unsigned int' foo.cc:3: in passing argument 1 of `foo(unsigned int &)' Therefore, the fact that changing the declaration of a from unsigned to int allows the compiler to complete without warning or error is the true bug. In line 10, (unsigned) a is an rvalue, which cannot be assigned to the non-const unsigned & of foo(). The correct cast in this situation would be (unsigned &) a, which does work as expected. -- Eric Blake
next reply other threads:[~2001-04-01 0:00 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-04-01 0:00 Eric Blake [this message] -- strict thread matches above, loose matches on Subject: below -- 2003-05-06 0:16 c++/1920 Wolfgang Bangerth 2001-04-01 0:00 c++/1920 jbuck 2001-04-01 0:00 c++/1920 Joe Buck
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=20010209225600.10926.qmail@sourceware.cygnus.com \ --to=ebb9@email.byu.edu \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@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: linkBe 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).