From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3091 invoked by alias); 27 Jul 2011 10:07:34 -0000 Received: (qmail 3076 invoked by uid 22791); 27 Jul 2011 10:07:33 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 Jul 2011 10:07:19 +0000 From: "antomicx at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/49863] New: -Wunused-result not behaving correctly X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: antomicx at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Wed, 27 Jul 2011 10:07:00 -0000 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: 2011-07/txt/msg02318.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D49863 Summary: -Wunused-result not behaving correctly Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: antomicx@gmail.com With a snippet as simple as the following # cat main.c #include int main() { system("ls"); return 0; } I'm getting these, different, compilation results: 1) # gcc main.c Output: empty 2) # gcc -Wunused-result main.c Output: empty 3) # gcc -W -Wall -Wextra main.c Output: empty 4) # gcc -W -Wall -Wextra -Wunused-result main.c Output: empty 5) # gcc -O0 -W -Wall -Wextra -Wunused-result main.c=20 Output: empty 6) # gcc -O1 main.c # same thing with -O2 -O3 Output:=20 main.c: In function =E2=80=98main=E2=80=99: main.c:4:9: warning: ignoring return value of =E2=80=98system=E2=80=99, dec= lared with attribute warn_unused_result Why is putting -Ox with x > 0 the only way to get the correct compilation warning when invoking the 'system' call without parsing its result? # gcc -v Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/= lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=3Dc,c++,fortran,objc,obj-c++ --prefix=3D/usr --program-suffix=3D-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=3Dx86_64-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=3D/usr/lib/x86_64-linux-gnu --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.5 --libdir=3D/usr/lib/x86_64-li= nux-gnu --enable-nls --with-sysroot=3D/ --enable-clocale=3Dgnu --enable-libstdcxx-d= ebug --enable-libstdcxx-time=3Dyes --enable-plugin --enable-gold --enable-ld=3Dd= efault --with-plugin-ld=3Dld.gold --enable-objc-gc --disable-werror --with-arch-32= =3Di686 --with-tune=3Dgeneric --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu Thread model: posix gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)