From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27149 invoked by alias); 29 Jan 2015 02:35:44 -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 Received: (qmail 26934 invoked by uid 48); 29 Jan 2015 02:35:36 -0000 From: "bernd.edlinger at hotmail dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64852] New: C++ accepts invalid(?) constants only at -O0 Date: Thu, 29 Jan 2015 02:35: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-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bernd.edlinger at hotmail dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg03339.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64852 Bug ID: 64852 Summary: C++ accepts invalid(?) constants only at -O0 Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bernd.edlinger at hotmail dot de This program should probably be rejected, but actually it compiles correctly and without warning, the resulting code "works". Same behaviour with current trunk and 4.6.2 cat test.C #include #include const short test = htons(10); int main() { printf("%x\n", test); } g++ -O0 test.C && ./a.out a00 g++ -O1 test.C In file included from /usr/include/x86_64-linux-gnu/bits/byteswap.h:35:0, from /usr/include/endian.h:60, from /usr/include/x86_64-linux-gnu/sys/types.h:216, from /usr/include/x86_64-linux-gnu/sys/uio.h:23, from /usr/include/x86_64-linux-gnu/sys/socket.h:26, from /usr/include/netinet/in.h:23, from /usr/include/arpa/inet.h:22, from test.C:1: test.C:4:20: error: statement-expressions are not allowed outside functions nor in template-argument lists const short test = htons(10); the same program is correctly rejected if compiled in C mode, but interestingly with a completely different message on -O0 and -O1