public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36478]  New: [4.3/4.4 regression] warning not emitted when code expanded from macro
@ 2008-06-09 16:34 tromey at gcc dot gnu dot org
  2008-06-10  9:51 ` [Bug c++/36478] " rguenth at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tromey at gcc dot gnu dot org @ 2008-06-09 16:34 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1548 bytes --]

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
@ 2008-06-10  9:51 ` rguenth at gcc dot gnu dot org
  2008-07-31 12:23 ` dodji at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-06-10  9:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-06-10 09:50 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
           Priority|P3                          |P2
   Last reconfirmed|0000-00-00 00:00:00         |2008-06-10 09:50:40
               date|                            |
   Target Milestone|---                         |4.3.2


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
  2008-06-10  9:51 ` [Bug c++/36478] " rguenth at gcc dot gnu dot org
@ 2008-07-31 12:23 ` dodji at gcc dot gnu dot org
  2008-08-11 12:33 ` manu at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dodji at gcc dot gnu dot org @ 2008-07-31 12:23 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]



------- Comment #2 from dodji at gcc dot gnu dot org  2008-07-31 12:22 -------
Created an attachment (id=15984)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15984&action=view)
candidate partial fix

This patch fixes the problem patially.

if you have:
------------
void  
foo ()
{
#define WARNS while(0)
#define DOES_NOT_WARN while(0); 
        WARNS; // { dg-warning }
        DOES_NOT_WARN;
            while (0); // { dg-warning }
}
---------------

The compiler (augmented with the patch) says:
/home/dodji/devel/src/gcc-bug-test.cc:6: warning: suggest a space before ‘;’ or
explicit braces around empty body in ‘while’ statement
/home/dodji/devel/src/gcc-bug-test.cc:8: warning: suggest a space before ‘;’ or
explicit braces around empty body in ‘while’ statement


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
  2008-06-10  9:51 ` [Bug c++/36478] " rguenth at gcc dot gnu dot org
  2008-07-31 12:23 ` dodji at gcc dot gnu dot org
@ 2008-08-11 12:33 ` manu at gcc dot gnu dot org
  2008-08-27 22:10 ` jsm28 at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-11 12:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2008-08-11 12:32 -------
(In reply to comment #2)
> void  
> foo ()
> {
> #define WARNS while(0)
> #define DOES_NOT_WARN while(0); 
>         WARNS; // { dg-warning }
>         DOES_NOT_WARN;

I don't think we want to warn here. Even if we have the right location of ')',
this would be hard to warn. How do you distinguish?

DOES_NOT_WARN;
DOES_NOT_WARN/**/;

That said, I don't think tracking the end of the macro is a good idea either.
It just moves the problem around. Another workaround would be to not check
close_paren.column + 1 == semicolon.column since it is the next token and
before the semicolon there is no whitespace. The only problem is if there is a
comment, such as while(0)/**/; and we have no way to track that, have we?.

For a proper fix, we need at least 2 locations for each token that comes from
an expansion. The place where the token really appeared and the place where it
ended up. However, this is not trivial. We need either to encode such
information in 1 location_t number somehow or to encode it in the token.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-08-11 12:33 ` manu at gcc dot gnu dot org
@ 2008-08-27 22:10 ` jsm28 at gcc dot gnu dot org
  2008-11-10 10:16 ` jakub at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-08-27 22:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jsm28 at gcc dot gnu dot org  2008-08-27 22:04 -------
4.3.2 is released, changing milestones to 4.3.3.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.2                       |4.3.3


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-08-27 22:10 ` jsm28 at gcc dot gnu dot org
@ 2008-11-10 10:16 ` jakub at gcc dot gnu dot org
  2008-11-10 13:54 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-11-10 10:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2008-11-10 10:15 -------
2 locations won't help you either.
void foo ()
{
#define EMPTY
  while (0)EMPTY;
}
won't warn when compiled with g++ -Wempty-body -O2, but will with
g++ -Wempty-body -O2 -save-temps (i.e. ccache etc.).  I think it is unfortunate
this -Wempty-body extension was accepted for 4.3, and if we want to make it
work, we really have to handle it at the preprocessor level.


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-11-10 10:16 ` jakub at gcc dot gnu dot org
@ 2008-11-10 13:54 ` jakub at gcc dot gnu dot org
  2008-11-12 22:21 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-11-10 13:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2008-11-10 13:53 -------
Patch posted.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2008-
                   |                            |11/msg00361.html
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-06-10 09:50:40         |2008-11-10 13:53:26
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3/4.4 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-11-10 13:54 ` jakub at gcc dot gnu dot org
@ 2008-11-12 22:21 ` jakub at gcc dot gnu dot org
  2009-01-24 10:24 ` [Bug c++/36478] [4.3 " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-11-12 22:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jakub at gcc dot gnu dot org  2008-11-12 22:19 -------
Subject: Bug 36478

Author: jakub
Date: Wed Nov 12 22:18:03 2008
New Revision: 141810

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141810
Log:
        PR c++/36478
        Revert:
        2007-05-07  Mike Stump  <mrs@apple.com>
        * doc/invoke.texi (Warning Options): Document that -Wempty-body
        also checks for and while statements in C++.

        Revert:
        2007-05-07  Mike Stump  <mrs@apple.com>
        * parser.c (check_empty_body): Add.
        (cp_parser_iteration_statement): Add call to check_empty_body.

        * g++.old-deja/g++.mike/empty.C: Remove.

Removed:
    trunk/gcc/testsuite/g++.old-deja/g++.mike/empty.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2008-11-12 22:21 ` jakub at gcc dot gnu dot org
@ 2009-01-24 10:24 ` rguenth at gcc dot gnu dot org
  2009-08-04 12:41 ` rguenth at gcc dot gnu dot org
  2010-05-22 18:32 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-24 10:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2009-01-24 10:20 -------
GCC 4.3.3 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.3                       |4.3.4


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2009-01-24 10:24 ` [Bug c++/36478] [4.3 " rguenth at gcc dot gnu dot org
@ 2009-08-04 12:41 ` rguenth at gcc dot gnu dot org
  2010-05-22 18:32 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-04 12:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2009-08-04 12:29 -------
GCC 4.3.4 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.4                       |4.3.5


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/36478] [4.3 regression] warning not emitted when code expanded from macro
  2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2009-08-04 12:41 ` rguenth at gcc dot gnu dot org
@ 2010-05-22 18:32 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-22 18:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2010-05-22 18:12 -------
GCC 4.3.5 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.5                       |4.3.6


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-05-22 18:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-09 16:34 [Bug c++/36478] New: [4.3/4.4 regression] warning not emitted when code expanded from macro tromey at gcc dot gnu dot org
2008-06-10  9:51 ` [Bug c++/36478] " rguenth at gcc dot gnu dot org
2008-07-31 12:23 ` dodji at gcc dot gnu dot org
2008-08-11 12:33 ` manu at gcc dot gnu dot org
2008-08-27 22:10 ` jsm28 at gcc dot gnu dot org
2008-11-10 10:16 ` jakub at gcc dot gnu dot org
2008-11-10 13:54 ` jakub at gcc dot gnu dot org
2008-11-12 22:21 ` jakub at gcc dot gnu dot org
2009-01-24 10:24 ` [Bug c++/36478] [4.3 " rguenth at gcc dot gnu dot org
2009-08-04 12:41 ` rguenth at gcc dot gnu dot org
2010-05-22 18:32 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).