This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12667] [3.3 regression] max(enum) returns reference to temporary
- From: "mdorey at bluearc dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Nov 2003 07:16:18 -0000
- Subject: [Bug c++/12667] [3.3 regression] max(enum) returns reference to temporary
- References: <20031017235414.12667.mdorey@bluearc.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From mdorey at bluearc dot com 2003-11-20 07:16 -------
(In reply to comment #7)
> No, the temporaries last until the end of the full expression.
Just so but, for any sceptics in the audience, this produces similarly
incorrect output:
trevithick:~/playpen$ cat max-enum3.cpp && g++ -W -Wall -pedantic -v -O2 max-
enum3.cpp && ./a.out
#include <iostream>
enum E {
E1, E2
};
const E& max2(const E& a, const E& b) {
return a < b ? b : a;
}
int main() {
E e1 = E1;
E e2 = E2;
std::cout << max2(e1, e2) << std::endl;
}
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,objc,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=gnu --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-enum3.cpp -
D__GNUG__=3 -quiet -dumpbase max-enum3.cpp -auxbase max-enum3 -O2 -W -Wall -
pedantic -version -o /tmp/ccHEBlEU.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=98 --param ggc-min-heapsize=129171
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-enum3.cpp: In function `const E& max2(const E&, const E&)':
max-enum3.cpp:6: warning: returning reference to temporary
as -V -Qy -o /tmp/ccALcrp6.o /tmp/ccHEBlEU.s
GNU assembler version 2.14.90.0.7 (i386-linux) using BFD version 2.14.90.0.7
20031029 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/ccALcrp6.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -
lgcc /usr/lib/gcc-lib/i486-linux/3.3.2/crtend.o /usr/lib/gcc-lib/i486-
linux/3.3.2/../../../crtn.o
-1073744148
Cheers,
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12667