Bug 1022049 - macro seems to thwart "return with no value" warning
Summary: macro seems to thwart "return with no value" warning
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-10-22 14:36 UTC by Dan Winship
Modified: 2013-10-22 16:47 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-10-22 14:42:20 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

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...


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