Bug 1250848 - Missing compiler warnings from GLib runtime check macros
Summary: Missing compiler warnings from GLib runtime check macros
Alias: None
Product: Fedora
Classification: Fedora
Component: glib2
Version: 22
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Matthias Clasen
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2015-08-06 07:09 UTC by Milan Crha
Modified: 2015-08-06 08:53 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2015-08-06 08:51:45 UTC
Type: Bug

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

System ID Private Priority Status Summary Last Updated
GNOME Bugzilla 753310 0 None None None Never

Description Milan Crha 2015-08-06 07:09:37 UTC
Created attachment 1059733 [details]

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

Comment 1 Milan Crha 2015-08-06 07:15:59 UTC
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 07:18:57 UTC
(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 08:51:45 UTC
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:

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