Bug 1250848 - Missing compiler warnings from GLib runtime check macros
Missing compiler warnings from GLib runtime check macros
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: glib2 (Show other bugs)
22
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Matthias Clasen
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-08-06 03:09 EDT by Milan Crha
Modified: 2015-08-06 04:53 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-08-06 04:51:45 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
test.c (1.42 KB, text/plain)
2015-08-06 03:09 EDT, Milan Crha
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
GNOME Desktop 753310 None None None Never

  None (edit)
Description Milan Crha 2015-08-06 03:09:37 EDT
Created attachment 1059733 [details]
test.c

Please see the attached test.c file. There are three types of functions, which should produce the same compiler warnings about function return values, but they do not. I do not understand why. The first line contains a command line to compile the code.

The first set of functions, prefixed with "direct_", uses direct 'return' statements, which gcc catches nicely and warns about issues.

The second set of functions, prefixed with "macro_", uses GLib's g_return{_val}_if_fail() macros, in the same way as the "direct_" functions, thus I expect to be warned about them. I get no warning here.

The last function, my_macro_missing_return_func(), uses cop&pasted g_return_if_fail() macro from /usr/include/glib-2.0/glib/gmessages.h, only renamed to my_return_if_fail(), about which the gcc claims the compiler warning, just as expected.

As the macro expansion works in case of the last function, I expect it to work the same in the second set of functions, but it doesn't. I know the macros are used, because I see the warnings in the runtime.

$ gcc --version
gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Milan Crha 2015-08-06 03:15:59 EDT
There is a comment at [1]:
> I found glib/gmessages.h contains this:
>
> /* Suppress warnings when GCC is in -pedantic mode and not -std=c99 */
> #if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
> #pragma GCC system_header
> #endif
>
>
> so warnings caused by g_return_if_fail and g_return_val_if_fail are suppressed.

but even if I add -pedantic and -std=c99 into the command line, then I'm not warned during the compile time. (Why would anyone disable these warnings anyway?)

[1] https://bugzilla.gnome.org/show_bug.cgi?id=753276#c5
Comment 2 Milan Crha 2015-08-06 03:18:57 EDT
(In reply to Milan Crha from comment #1)
> but even if I add -pedantic and -std=c99 into the command line, then I'm not
> warned during the compile time.

It might be just other compiler flags to enable the warnings, because if I manually disable the quoted code then the warnings are shown as expected.
Comment 3 Milan Crha 2015-08-06 04:51:45 EDT
Thinking of it, it's glib's issue, the check doesn't seem to do what it claims to do, thus let's move this upstream:
https://bugzilla.gnome.org/show_bug.cgi?id=753310

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