Bug 31063 - Spurious/missing warn_unused_result warnings affected by presence/absense of copy constructor
Summary: Spurious/missing warn_unused_result warnings affected by presence/absense of ...
Status: RESOLVED DUPLICATE of bug 38172
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-03-06 22:23 UTC by Fletcher Dunn
Modified: 2008-11-18 22:14 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Repro code with the proper line breaks (1009 bytes, text/plain)
2007-03-06 22:26 UTC, Fletcher Dunn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fletcher Dunn 2007-03-06 22:23:22 UTC
// 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
//
Comment 1 Fletcher Dunn 2007-03-06 22:26:04 UTC
Created attachment 13155 [details]
Repro code with the proper line breaks

Line breaks got messed up when pasting into bug description.
Comment 2 Andrew Pinski 2007-03-06 22:40:56 UTC
// 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.

You should have filed this first with Sony.  We (Sony) do change the bug reporting address to the correct one for the PS3 toolchain.

Thanks,
Andrew Pinski
Sony Compiler Engineer
Comment 3 Andrew Pinski 2008-11-18 22:14:57 UTC
PR 38172 has the better example.

*** This bug has been marked as a duplicate of 38172 ***