From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29168 invoked by alias); 6 Mar 2007 22:23:32 -0000 Received: (qmail 29157 invoked by uid 48); 6 Mar 2007 22:23:22 -0000 Date: Tue, 06 Mar 2007 22:23:00 -0000 Subject: [Bug c++/31063] New: Spurrious/missing warn_unused_result warnings affected by presence/absense of copy constructor X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "fletcherdunn at yahoo dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg00428.txt.bz2 // Illustrates some bugs related to __attribute__((warn_unused_result)). struct Vector { float x, y, z; inline Vector() {} inline Vector(float _x,float _y,float _z) : x(_x), y(_y), z(_z) {} // BUG: Toggling the presence of a copy constructor (doesn't matter which // of the ones below you use) will affect the generation of the warnings. inline Vector(const Vector &a) { x = a.x; y = a.y; z = a.z; } // inline Vector(const Vector &a) : x(a.x), y(a.y), z(a.z) {} inline Vector operator-(const Vector &a) const __attribute__((warn_unused_result)) { return Vector(x - a.x, y - a.y, z - a.z ); } }; struct Box { Vector min, max; // BUG: generates spurrious warning about not using result from operator-. // If you remove the copy constructor, the warning goes away inline Vector size() const { return max - min; } }; void foo() { Vector a, b; // BUG: this *should* generate a warning, but you will only get a warning // if you have the copy constructor. If you remove the copy constructor, // the warning goes away a-b; } // // Output with copy constructor defined: // // $ /c/usr/local/cell/host-win32/ppu/ppu-lv2/bin/gcc -v -save-temps -c -Wall warn_unused_result_bug_2.cpp // Using built-in specs. // Target: ppu-lv2 // Configured with: /export/fukuoka/ps3-svn/toolchain/trunk/gcc/configure --target=ppu-lv2 --host=i386-pc-mingw32msvc --build=i686-pc-linux-gnu --prefix=/usr/local/cell/host-win32/ppu --with-sysroot=/usr/local/cell/target/ppu --with-headers=yes --disable-threads --disable-shared --disable-hosted-libstdcxx // Thread model: single // gcc version 4.0.2 (CELL 4.1.19, $Rev: 1341 $) // /usr/local/cell/host-win32/ppu/libexec/gcc/ppu-lv2/4.0.2/cc1plus.exe -E -quiet -v -iprefix c:\usr\local\cell\host-win32\ppu\ppu-lv2\bin\../lib/gcc/ppu-lv2/4.0.2/ -D__PPU__ -D__CELLOS_LV2__ warn_unused_result_bug_2.cpp -mabi=altivec -maltivec -mstrict-align -fstrict-aligned -mvrsave=no -mtraceback=none -Wall -fpch-preprocess -fno-threadsafe-statics -o warn_unused_result_bug_2.ii // ignoring nonexistent directory "c:/usr/local/cell/host-win32/ppu/ppu-lv2/bin/../lib/gcc/ppu-lv2/4.0.2/include" // #include "..." search starts here: // #include <...> search starts here: // /usr/local/cell/host-win32/ppu/lib/gcc/ppu-lv2/4.0.2/include // /usr/local/cell/target/ppu/include // /usr/local/cell/target/ppu/include/sys // /usr/local/cell/target/ppu/../common/include // End of search list. // /usr/local/cell/host-win32/ppu/libexec/gcc/ppu-lv2/4.0.2/cc1plus.exe -fpreprocessed warn_unused_result_bug_2.ii -mabi=altivec -maltivec -mstrict-align -fstrict-aligned -mvrsave=no -mtraceback=none -quiet -dumpbase warn_unused_result_bug_2.cpp -auxbase warn_unused_result_bug_2 -Wall -version -fno-threadsafe-statics -o warn_unused_result_bug_2.s // GNU C++ version 4.0.2 (CELL 4.1.19, $Rev: 1341 $) (ppu-lv2) // compiled by GNU C version 4.0.2 (CELL 4.1.19, $Rev: 1341 $). // GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=130941 // warn_unused_result_bug_2.cpp: In member function 'Vector Box::size() const': // warn_unused_result_bug_2.cpp:23: warning: ignoring return value of 'Vector Vector::operator-(const Vector&) const', declared with attribute warn_unused_result // warn_unused_result_bug_2.cpp: In function 'void foo()': // warn_unused_result_bug_2.cpp:32: warning: ignoring return value of 'Vector Vector::operator-(const Vector&) const', declared with attribute warn_unused_result // // If you comment out the copy constructor, the warnings do not appear. // Note that I produced this with the Playstation (CELL) version of GCC under // MinGW/MSys, but I don't think this is a platform specific issues. // // gccc --version produces this: // gcc.exe (GCC) 4.0.2 (CELL 4.1.19, $Rev: 1341 $) // Copyright (C) 2005 Free Software Foundation, Inc. // This is free software; see the source for copying conditions. There is NO // warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // // This might be a dup of either of these issues: // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27370 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27371 // // Cheers, // fletcherdunn --at-- yahoo.com // -- Summary: Spurrious/missing warn_unused_result warnings affected by presence/absense of copy constructor Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fletcherdunn at yahoo dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31063