Bug 1105335 - assert (errno = ENOENT) cannot be detected by gcc -Wparentheses
Summary: assert (errno = ENOENT) cannot be detected by gcc -Wparentheses
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: rawhide
Hardware: All
OS: All
unspecified
unspecified
Target Milestone: ---
Assignee: Carlos O'Donell
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-06-05 22:24 UTC by Jim Meyering
Modified: 2016-12-19 07:32 UTC (History)
6 users (show)

Fixed In Version: glibc-2.24.90-24.fc26
Clone Of:
Environment:
Last Closed: 2016-12-19 07:32:58 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
define gcc--Wparentheses-friendly assert macro (1.83 KB, text/plain)
2014-06-05 22:24 UTC, Jim Meyering
no flags Details
adjusted to use statement expression instead of do...while(0) (1.83 KB, text/plain)
2014-06-05 23:45 UTC, Jim Meyering
no flags Details
assert: fix its definition not to disable -Wparentheses (2.39 KB, patch)
2014-07-05 22:31 UTC, Jim Meyering
no flags Details | Diff
better patch (1.81 KB, patch)
2014-07-16 17:23 UTC, Jim Meyering
no flags Details | Diff
better patch (1.72 KB, patch)
2014-07-16 17:39 UTC, Jim Meyering
no flags Details | Diff
still better (1.73 KB, patch)
2014-07-16 23:16 UTC, Jim Meyering
no flags Details | Diff
improved patch (2.02 KB, patch)
2016-11-24 02:58 UTC, Jim Meyering
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Sourceware 20386 0 None None None 2016-07-19 11:59:22 UTC

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


Note You need to log in before you can comment on or make changes to this bug.