Bug 1022049

Summary: macro seems to thwart "return with no value" warning
Product: [Fedora] Fedora Reporter: Dan Winship <danw>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 20CC: jakub, law
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-22 14:42:20 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:

Description Dan Winship 2013-10-22 14:36:17 UTC
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 14:42:20 UTC
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 16:47:26 UTC
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...