This is a copy of a bug report from Red Hat's bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=449191

The bug is that with mapped locations, the code in check_empty_body
does not notice that the while() from the macro expansion violates the
rule.  This is because of the hack we needed to get decent error messages
with mapped locations -- tokens resulting from a macro expansion are all
given the location of the start of the expansion.


Steps to Reproduce:
1. compile example program:

> cat warn2.cc
int
main(int, char**)
{
#define XXX while(0);
    XXX ;
    while (0);
}

> g++ -W -Werror -c warn2.cc

Actual results:
cc1plus: warnings being treated as errors
warn2.cc: In function ‘int main(int, char**)’:
warn2.cc:6: error: suggest a space before ‘;’ or explicit braces around empty
body in ‘while’ statement


Expected results:
warn2.cc: In function ‘int main(int, char**)’:
warn2.cc:5: warning: suggest a space before ‘;’ or explicit braces around empty
body in ‘while’ statement
warn2.cc:6: warning: suggest a space before ‘;’ or explicit braces around empty
body in ‘while’ statement


-- 
           Summary: [4.3/4.4 regression] warning not emitted when code
                    expanded from macro
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tromey at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36478

Reply via email to