public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma  doesn't for -Wunused-local-typedefs
@ 2012-05-24  9:32 burnus at gcc dot gnu.org
  2012-05-25 12:54 ` [Bug c++/53469] " dodji at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-24  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53469
           Summary: #pragma GCC diagnostic works, but using _Pragma
                    doesn't for -Wunused-local-typedefs
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: dodji@gcc.gnu.org


Since GCC 4.7, the new warning -Wunused-local-typedefs is supported (PR
c++/33255, 2011-09-08); since GCC 4.8 (2012-05-04) it is enabled by -Wall and
-Wunused.


A typedef was used in a compile-time check whether an expression is constant
(compile-time assert). To allow for the new check but selectively disable the
warning for that line, I tried a pragma.


While using #pragma directly works, using _Pragma fails. The following example
shows no warning for "foo" but for "bar" it fails with:

test.cc:19:14: error: typedef ‘myint’ locally defined but not used
[-Werror=unused-local-typedefs]


Expected: _Pragma has the same result as writing #pragma.



#pragma GCC diagnostic error "-Wunused-local-typedefs"

// Works:

void foo ()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
  typedef int myint;
#pragma GCC diagnostic pop
}


// Fails:

#define STRINGIFY(x) #x
#define TEST(x) \
 _Pragma(STRINGIFY(GCC diagnostic ignored "-Wunused-local-typedefs")) \
 typedef int myint;
// _Pragma(STRINGIFY(GCC diagnostic pop))
void bar ()
{
  TEST(myint)
}


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

* [Bug c++/53469] #pragma GCC diagnostic works, but using _Pragma  doesn't for -Wunused-local-typedefs
  2012-05-24  9:32 [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs burnus at gcc dot gnu.org
@ 2012-05-25 12:54 ` dodji at gcc dot gnu.org
  2012-05-29 10:25 ` [Bug preprocessor/53469] " dodji at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-05-25 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

Dodji Seketeli <dodji at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-05-25
         AssignedTo|unassigned at gcc dot       |dodji at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug preprocessor/53469] #pragma GCC diagnostic works, but using _Pragma  doesn't for -Wunused-local-typedefs
  2012-05-24  9:32 [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs burnus at gcc dot gnu.org
  2012-05-25 12:54 ` [Bug c++/53469] " dodji at gcc dot gnu.org
@ 2012-05-29 10:25 ` dodji at gcc dot gnu.org
  2012-08-27 15:42 ` dodji at gcc dot gnu.org
  2012-08-27 15:45 ` dodji at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-05-29 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Dodji Seketeli <dodji at gcc dot gnu.org> 2012-05-29 10:20:52 UTC ---
I candidate fix was proposed to
http://gcc.gnu.org/ml/gcc-patches/2012-05/msg01899.html


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

* [Bug preprocessor/53469] #pragma GCC diagnostic works, but using _Pragma  doesn't for -Wunused-local-typedefs
  2012-05-24  9:32 [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs burnus at gcc dot gnu.org
  2012-05-25 12:54 ` [Bug c++/53469] " dodji at gcc dot gnu.org
  2012-05-29 10:25 ` [Bug preprocessor/53469] " dodji at gcc dot gnu.org
@ 2012-08-27 15:42 ` dodji at gcc dot gnu.org
  2012-08-27 15:45 ` dodji at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-08-27 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Dodji Seketeli <dodji at gcc dot gnu.org> 2012-08-27 15:41:44 UTC ---
Author: dodji
Date: Mon Aug 27 15:41:38 2012
New Revision: 190714

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190714
Log:
PR preprocessor/53469 - argument tokens of _Pragma miss virtual location

Consider this short test snippet:

-------------------------8-------------------
    #define STRINGIFY(x) #x
    #define TEST(x) \
      _Pragma(STRINGIFY(GCC diagnostic ignored "-Wunused-local-typedefs")) \
      typedef int myint;

    void bar ()
    {
      TEST(myint)
    }
-------------------------8-------------------

The _Pragma is effectively ignored, and compiling with
-Wunused-local-typedefs warns on the local typedef, even though the
pragma should have prevented the warning to be emitted.

This is because when the preprocessor sees the _Pragma operator and
then goes to handle the first token ('GCC' here) that makes up its
operands, it retains the spelling location of that token, not its
virtual location.

Later when diagnostic_report_diagnostic is called to emit the warning
(or ignore it because of the pragma), it compares the location of the
first operand of the pragma with the location of the unused location,
(by calling linemap_location_before_p) and that comparison fails
because in this case, both locations should be virtual.

This patch fixes the issue by teaching the pragma handling to use
virtual locations.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

libcpp/

    PR preprocessor/53469
    * directives.c (do_pragma): Use the virtual location for the
    pragma token, instead of its spelling location.

gcc/testsuite/

    PR preprocessor/53469
    * gcc.dg/cpp/_Pragma7.c: New test case.

Added:
    trunk/gcc/testsuite/gcc.dg/cpp/_Pragma7.c
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libcpp/ChangeLog
    trunk/libcpp/directives.c


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

* [Bug preprocessor/53469] #pragma GCC diagnostic works, but using _Pragma  doesn't for -Wunused-local-typedefs
  2012-05-24  9:32 [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-08-27 15:42 ` dodji at gcc dot gnu.org
@ 2012-08-27 15:45 ` dodji at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-08-27 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

Dodji Seketeli <dodji at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Dodji Seketeli <dodji at gcc dot gnu.org> 2012-08-27 15:45:33 UTC ---
Fixed in trunk (4.8).


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

end of thread, other threads:[~2012-08-27 15:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-24  9:32 [Bug c++/53469] New: #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs burnus at gcc dot gnu.org
2012-05-25 12:54 ` [Bug c++/53469] " dodji at gcc dot gnu.org
2012-05-29 10:25 ` [Bug preprocessor/53469] " dodji at gcc dot gnu.org
2012-08-27 15:42 ` dodji at gcc dot gnu.org
2012-08-27 15:45 ` dodji at gcc dot gnu.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).