Bug 1105335

Summary: assert (errno = ENOENT) cannot be detected by gcc -Wparentheses
Product: [Fedora] Fedora Reporter: Jim Meyering <jim>
Component: glibcAssignee: Carlos O'Donell <codonell>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: codonell, fweimer, jakub, law, mnewsome, pfrankli
Target Milestone: ---Keywords: FutureFeature, Reopened
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: glibc-2.24.90-24.fc26 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-19 07:32:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
define gcc--Wparentheses-friendly assert macro
none
adjusted to use statement expression instead of do...while(0)
none
assert: fix its definition not to disable -Wparentheses
none
better patch
none
better patch
none
still better
none
improved patch none

Description Jim Meyering 2014-06-05 22:24:11 UTC
Created attachment 902693 [details]
define gcc--Wparentheses-friendly assert macro

Description of problem:
 "assert (errno = ENOENT);" does not elicit a warning from gcc -Wparentheses

This is not a bug, but a request for improvement.

Replace glibc's assert macro with a version that does not add parentheses.
The default non-empty expansion of assert parenthesizes "expr", and, by
enclosing it in parentheses, effectively disables gcc's usual -Wparentheses
(part of -Wall) warning.  That is the warning that catches the mistake of
"if (a = b) ..." when "if (a == b) ..."  was intended.  Thus, with the
default assert definition, gcc cannot warn about the erroneous
"assert(a = 1)", but with this replacement, it does.

Version-Release number of selected component (if applicable):
  all

How reproducible: every time

Steps to Reproduce:
printf '%s\n' '#include <assert.h>' \
   'int main() {int a = 1; assert (a = 0); return a;}' > k.c \
  && gcc -Wparentheses k.c

Actual results:
  no warning

Desired results:
  a warning like this:

    k.c:2:1: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

Additional info:
patch attached

Comment 1 Jim Meyering 2014-06-05 23:45:39 UTC
Created attachment 902724 [details]
adjusted to use statement expression instead of do...while(0)

Comment 2 Jim Meyering 2014-06-05 23:46:54 UTC
Hmm... but using statement expressions may have to be conditional upon not disabling extensions.

Comment 3 Jim Meyering 2014-07-05 22:31:54 UTC
Created attachment 914882 [details]
assert: fix its definition not to disable -Wparentheses

handle __STRICT_ANSI__, too

Comment 4 Jim Meyering 2014-07-16 17:23:23 UTC
Created attachment 918486 [details]
better patch

Add __GNUC__ guard, and fix a typo.

Comment 5 Jim Meyering 2014-07-16 17:39:31 UTC
Created attachment 918491 [details]
better patch

The previous was not the new version.  Also fix spaces-vs-TABs.

Comment 6 Jim Meyering 2014-07-16 23:16:20 UTC
Created attachment 918554 [details]
still better

Use __extension__

Comment 7 Jaroslav Reznik 2015-03-03 15:52:30 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 22 development cycle.
Changing version to '22'.

More information and reason for this action is here:
https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora22

Comment 8 Fedora End Of Life 2016-07-19 11:37:10 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 9 Florian Weimer 2016-07-19 11:59:23 UTC
Upstream discussion:

https://sourceware.org/ml/libc-alpha/2014-07/msg00394.html

Comment 10 Jim Meyering 2016-11-24 02:58:27 UTC
Created attachment 1223507 [details]
improved patch