From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109643 invoked by alias); 2 Sep 2015 10:59:30 -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 109429 invoked by uid 48); 2 Sep 2015 10:59:25 -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 10:59: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: RESOLVED X-Bugzilla-Resolution: INVALID 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: 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/msg00152.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433 --- Comment #12 from xuejuncao --- (In reply to Richard Biener from comment #11) > (In reply to xuejuncao from comment #10) > > when bool value read from unpacked stream or file, wen can not ensure it's 1 > > or 0; > > so maybe the best solution is compile with "-D_Bool=char" for now :-/ > > You can always do the read with 'char' and then convert to _Bool. > > You can also "fix" your testcase (I think, didn't try) by using > > union u { > bool b : 1; > char c; > } u; > > (in case unions allow bitfield members) yes, it works, but likes a trick:-) bit operation to bool is also undefined int i = (u.b & 1 ? 1 : 0); // works without -O2, useless with -O2