From owner-freebsd-bugs@freebsd.org Sun Jul 31 10:04:33 2016 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C942DBA9909 for ; Sun, 31 Jul 2016 10:04:33 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AE2401993 for ; Sun, 31 Jul 2016 10:04:33 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id u6VA4X8X089234 for ; Sun, 31 Jul 2016 10:04:33 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 211475] clang++ 3.8.0 false warning: wrong type/value involved in compiler's false message Date: Sun, 31 Jul 2016 10:04:33 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 11.0-BETA3 X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: markmi@dsl-only.net X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jul 2016 10:04:33 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D211475 Bug ID: 211475 Summary: clang++ 3.8.0 false warning: wrong type/value involved in compiler's false message Product: Base System Version: 11.0-BETA3 Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: markmi@dsl-only.net The context here was a -r419343 /usr/ports based report, although later bel= ow I show a 9-line, simple source that shows the issue . . . devel/qmake5: . . ./corelib/tools/qmap.h:617:27: warning: returning address= of local temporary object when compiled under a 11.0-BETA3 context: devel/qmake5 gets several reports= of returning the address of a local temporary object. For example: --- metamakefile.o --- In file included from /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= qmake/generators/metamakefile.cpp:37: In file included from /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= include/QtCore/qdebug.h:1: In file included from /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= include/QtCore/../../src/corelib/io/qdebug.h:40: In file included from /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= include/QtCore/qmap.h:1: /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= include/QtCore/../../src/corelib/tools/qmap.h:617:27: warning: returning address of local temporary object [-Wreturn-stack-addres= s] return n ? n->value : adefaultValue; ^~~~~~~~~~~~~ /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= qmake/generators/win32/msvc_objectmodel.h:1064:32: note: in instantiation of member function 'QMap::value' requested here TreeNode *n =3D children.value(newNodeName); ^ /usr/obj/portswork/usr/ports/devel/qmake5/work/qtbase-opensource-src-5.5.1/= include/QtCore/../../src/corelib/tools/qmap.h:386:44: note: binding reference variable 'adefaultValue' here const T value(const Key &key, const T &defaultValue =3D T()) const; ^ ~~~ I'll not go through the details of this complicated context. A short source showing the problem is: # more wrong_type.cc=20 #include template const T value(const T &v =3D T()) { return v; } int main () { int* n =3D value(); return nullptr !=3D n; } which when compiled reports: # clang++ -std=3Dc++14 wrong_type.cc wrong_type.cc:3:64: warning: returning address of local temporary object [-Wreturn-stack-address] template const T value(const T &v =3D T()) { return v; } ^ wrong_type.cc:7:14: note: in instantiation of function template specializat= ion 'value' requested here int* n =3D value(); ^ wrong_type.cc:3:46: note: binding reference variable 'v' here template const T value(const T &v =3D T()) { return v; } ^ ~~~ 1 warning generated. Note that the "address of local temporary object" would have type int** in = this example and the value held would be a nullptr (translated to int*). T is in= t* above. The result of running the compiled result is: # ./a.out && echo test test So n does end up matching nullptr, as it should. It does not end up with the address of the local temporary object (which would not match nullptr). # clang++ -std=3Dc++11 -O0 wrong_type.cc gets the same messages and the same result. Similarly for -std=3Dc++98 or -std=3Dc++03. So the warning does not match the execution behavior and the issue exists f= or multiple c++ target-vintages. It appears that for now the specific type of warning can not be relied on. So this appears to be more than just a generic false-positive but an actual reference to the wrong type and wrong value in the warning: the actual retu= rn value in question is not a stack address at all. Originally I was going to report this against devel/qmake5 but as I analyzed the code and composed the submittal message I ended up with finding clang++= to be referencing the wrong type and wrong value for the context in its messag= e. It appears to me that the C++ code generated is correct. --=20 You are receiving this mail because: You are the assignee for the bug.=