From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20900 invoked by alias); 2 Sep 2015 07:53:53 -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 20875 invoked by uid 48); 2 Sep 2015 07:53:49 -0000 From: "xuejuncao at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/67433] ?: expression returns unexpected value when condition is a bool variable which memory is not true/false Date: Wed, 02 Sep 2015 07:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xuejuncao at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: short_desc Message-ID: In-Reply-To: References: 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-09/txt/msg00119.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433 xuejuncao changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|?: expresion returns |?: expression returns |unexpected value when |unexpected value when |condition is a bool |condition is a bool |variable and it's value |variable which memory is |above 1 |not true/false --- Comment #1 from xuejuncao --- #include #include #include int main() { union u { bool b; char c; } u; memset((void *)&u, -1, sizeof(u)); bool b = (u.b ? 1 : 0); int i = (u.b ? 1 : 0); int j = (u.b ? 1 : 2); printf("b = %d, i = %d, j = %d\n", b, i, j); return 0; } without optimisation, the output is: b = 1, i = 255, j = 1 with -O2, is: b = 255, i = 255, j = 1