Bug 1022049 - macro seems to thwart "return with no value" warning
macro seems to thwart "return with no value" warning
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
20
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-22 10:36 EDT by Dan Winship
Modified: 2013-10-22 12:47 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-10-22 10:42:20 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)

  None (edit)
Description Dan Winship 2013-10-22 10:36:17 EDT
gcc (gcc-4.8.2-1.fc20.x86_64) seems to be not noticing a
return-without-value when it occurs inside the expansion of
glib's g_return_if_fail() macro:

    danw@laptop:tmp> cat foo.c
    #include <glib.h>

    int
    main (int argc, char **argv)
    {
      g_return_if_fail (argc == 1);

      return 0;
    }

    danw@laptop:tmp> gcc -Wall -c foo.c `pkg-config --cflags --libs glib-2.0`
    danw@laptop:tmp> echo $?
    0

If you force it to expand the macro first, it does notice:

    danw@laptop:tmp> gcc -E -o foo-expanded.c foo.c `pkg-config --cflags glib-2.0`

    danw@laptop:tmp> tail -9 foo-expanded.c
    # 2 "foo.c" 2
    
    int
    main (int argc, char **argv)
    {
      do{ if (argc == 1) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__, "argc == 1"); return; }; }while (0);

      return 0;
    }

    danw@laptop:tmp> gcc -Wall -c foo-expanded.c `pkg-config --cflags --libs glib-2.0`
    foo.c: In function ‘main’:
    foo.c:6:108: error: ‘return’ with no value, in function returning non-void [-Werror=return-type]
       g_return_if_fail (argc == 1);
                                                                                                                ^
Comment 1 Jakub Jelinek 2013-10-22 10:42:20 EDT
That is intentional, glib.h is in a system header directory and thus the problem exists in a macro from a system header, warnings for system headers are as documented disabled by default, you need -Wsystem-headers to request it.
Comment 2 Dan Winship 2013-10-22 12:47:26 EDT
ah, oh yeah, i remember wanting that functionality (for *other people's* headers) in the past

The problem here is that it's not a bug in the system header, it's that my code is calling the wrong macro. (It should be using g_return_val_if_fail(), not g_return_if_fail().)

Not sure if there's any easy fix for this that wouldn't break other cases...

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