From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1016 invoked by alias); 13 Nov 2013 10:45:52 -0000 Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-bugs-owner@sourceware.org Received: (qmail 1006 invoked by uid 89); 13 Nov 2013 10:45:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail.ecoscentric.com Received: from Unknown (HELO mail.ecoscentric.com) (212.13.207.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 13 Nov 2013 10:45:12 +0000 Received: by mail.ecoscentric.com (Postfix, from userid 48) id 29861468000C; Wed, 13 Nov 2013 10:45:03 +0000 (GMT) From: bugzilla-daemon@bugs.ecos.sourceware.org To: unassigned@bugs.ecos.sourceware.org Subject: [Bug 1001915] New: Invalid assert definition Date: Wed, 13 Nov 2013 10:45:00 -0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: eCos X-Bugzilla-Component: POSIX X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: jsetoain@ucm.es X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: low X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://bugs.ecos.sourceware.org/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013/txt/msg00644.txt.bz2 Please do not reply to this email, use the link below. http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001915 Bug ID: 1001915 Summary: Invalid assert definition Product: eCos Version: 3.0 Target: All Architecture/Host All OS: Status: UNCONFIRMED Severity: major Priority: low Component: POSIX Assignee: unassigned@bugs.ecos.sourceware.org Reporter: jsetoain@ucm.es CC: ecos-bugs@ecos.sourceware.org According to ISO C, the assert macro must be an expression but it is defined as an statement (do { } while(0)). This definition causes trouble in several situation where "assert" is used as an expression. From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html "The assert() macro shall insert diagnostics into programs; it shall expand to a void expression." Right now it is defined as follows: # define assert( __bool ) \ do { \ if (0 == (__bool)) { \ fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n", \ #__bool, __FILE__, __LINE__); \ abort(); \ } \ } while(0) I propose changing it to something like this: # define assert(__bool) \ ((__bool) \ ? (void)(0) \ : assert_failed(#__bool, __FILE__, __LINE__) And then define assert_failed as something like: void assert_failed(const char* assertion, const char* file, const char* line ) { fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n", assertion, file, line ); abort(); } This way, assert always evaluates to a void expression, as demanded by the standard. (PS: The whole fix would take changes in other macros, I'm just illustrating the problem and the solution). -- You are receiving this mail because: You are the assignee for the bug.