public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mdorey at bluearc dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/12667] [3.3 regression] max(enum) returns reference to temporary
Date: Sat, 15 Nov 2003 14:07:00 -0000	[thread overview]
Message-ID: <20031115140700.7096.qmail@sources.redhat.com> (raw)
In-Reply-To: <20031017235414.12667.mdorey@bluearc.com>


------- Additional Comments From mdorey at bluearc dot com  2003-11-15 14:06 -------
(In reply to comment #2)
> but since I do not know if the code invokes undefined behavior, I am not
confirming this 
> one.

Thanks for your interest.  Perhaps this would be a convincing demonstration (if
you can reproduce it):

martind@kenny:~/playpen$ cat max-enum2.cpp
#include <iostream>
enum E {
    E1, E2
};
const E& max2(const E& a, const E& b) {
  return a < b ? b : a;
}
int main() {
  std::cout << max2(E1, E2) << std::endl;
}
martind@kenny:~/playpen$ g++ -W -Wall -pedantic -v -O2 max-enum2.cpp
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.2/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,ob
          jc,ada,treelang --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info            --with-gxx-include-dir=/usr/include/c++/3.3
--enable-shared --with-system-zlib -           -enable-nls
--without-included-gettext --enable-__cxa_atexit --enable-clocale=gn           u
--enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc  
         i486-linux
Thread model: posix
gcc version 3.3.2 (Debian)
 /usr/lib/gcc-lib/i486-linux/3.3.2/cc1plus -quiet -v -D__GNUC__=3 -D__GNUC_MINOR
          __=3 -D__GNUC_PATCHLEVEL__=2 -D_GNU_SOURCE max-enum2.cpp -D__GNUG__=3
-quiet -du           mpbase max-enum2.cpp -auxbase max-enum2 -O2 -W -Wall
-pedantic -version -o /tmp/           ccNFFKYd.s
GNU C++ version 3.3.2 (Debian) (i486-linux)
        compiled by GNU C version 3.3.2 (Debian).
GGC heuristics: --param ggc-min-expand=34 --param ggc-min-heapsize=7673
ignoring nonexistent directory "/usr/i486-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.3
 /usr/include/c++/3.3/i486-linux
 /usr/include/c++/3.3/backward
 /usr/local/include
 /usr/lib/gcc-lib/i486-linux/3.3.2/include
 /usr/include
End of search list.
max-enum2.cpp: In function `const E& max2(const E&, const E&)':
max-enum2.cpp:6: warning: returning reference to temporary
 as -V -Qy -o /tmp/ccFrrEWo.o /tmp/ccNFFKYd.s
GNU assembler version 2.14.90.0.7 (i386-linux) using BFD version 2.14.90.0.7 200
          31029 Debian GNU/Linux
 /usr/lib/gcc-lib/i486-linux/3.3.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-
          linker /lib/ld-linux.so.2
/usr/lib/gcc-lib/i486-linux/3.3.2/../../../crt1.o /usr          
/lib/gcc-lib/i486-linux/3.3.2/../../../crti.o /usr/lib/gcc-lib/i486-linux/3.3.2/
          crtbegin.o -L/usr/lib/gcc-lib/i486-linux/3.3.2
-L/usr/lib/gcc-lib/i486-linux/3.3           .2/../../.. /tmp/ccFrrEWo.o -lstdc++
-lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/li          
b/gcc-lib/i486-linux/3.3.2/crtend.o /usr/lib/gcc-lib/i486-linux/3.3.2/../../../c
          rtn.o
martind@kenny:~/playpen$ ./a.out
-1073742500
martind@kenny:~/playpen$ 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12667


  parent reply	other threads:[~2003-11-15 14:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-18  0:15 [Bug c++/12667] New: " mdorey at bluearc dot com
2003-10-18  0:46 ` [Bug c++/12667] " pinskia at gcc dot gnu dot org
2003-11-15 11:31 ` [Bug c++/12667] [3.3 regression] " pinskia at gcc dot gnu dot org
2003-11-15 14:07 ` mdorey at bluearc dot com [this message]
2003-11-16 17:47 ` bangerth at dealii dot org
2003-11-16 17:55 ` falk at debian dot org
2003-11-18  5:28 ` pinskia at gcc dot gnu dot org
2003-11-19  4:23 ` gdr at integrable-solutions dot net
2003-11-20  7:16 ` mdorey at bluearc dot com
2003-11-20  7:18 ` pinskia at gcc dot gnu dot org
2003-11-20  7:23 ` mdorey at bluearc dot com
2003-12-22 23:30 ` pinskia at gcc dot gnu dot org

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=20031115140700.7096.qmail@sources.redhat.com \
    --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).