From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7670 invoked by alias); 30 Apr 2012 10:20:07 -0000 Received: (qmail 7656 invoked by uid 22791); 30 Apr 2012 10:20:06 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Mon, 30 Apr 2012 10:19:53 +0000 From: "andyg1001 at hotmail dot co.uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53166] New: static_assert produces bogus warning Date: Mon, 30 Apr 2012 10:20:00 -0000 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: major X-Bugzilla-Who: andyg1001 at hotmail dot co.uk 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 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: 2012-04/txt/msg02595.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53166 Bug #: 53166 Summary: static_assert produces bogus warning Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: andyg1001@hotmail.co.uk The following code produces a bogus compilation warning: template struct A { static_assert(a !=3D nullptr, "oops"); }; int a1; A a2; // this produces a bogus warning A a3; // correctly generates static assertion The bogus warning is for the declaration of "a2" saying "the address of =E2= =80=98a1=E2=80=99 will never be NULL". This is, of course, true but is exactly what the static_assert is intended to ensure! (cf. the declaration of "a3"). Here is the output from gcc: $ gcc-4.7 -c --std=3Dc++11 bugreport.cpp -Wall -Werror bugreport.cpp: In instantiation of =E2=80=98struct A=E2=80=99: bugreport.cpp:7:14: required from here bugreport.cpp:2:10: error: the address of =E2=80=98a1=E2=80=99 will never b= e NULL [-Werror=3Daddress] bugreport.cpp: In instantiation of =E2=80=98struct A=E2=80=99: bugreport.cpp:8:18: required from here bugreport.cpp:3:5: error: static assertion failed: oops cc1plus: all warnings being treated as errors My expectation would be that the static_assert should silently pass, not ca= use a warning in this case. Compare the output that clang gives: bugreport.cpp:3:5: error: static_assert failed "oops" static_assert(a !=3D nullptr, "oops"); ^ ~~~~~~~~~~~~ bugreport.cpp:8:18: note: in instantiation of template class 'A' requested here=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 A a3; // correctly generates static assertion ^ 1 error generated.