From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24298 invoked by alias); 27 Aug 2012 15:42:00 -0000 Received: (qmail 24283 invoked by uid 22791); 27 Aug 2012 15:41:59 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Aug 2012 15:41:46 +0000 From: "dodji at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug preprocessor/53469] #pragma GCC diagnostic works, but using _Pragma doesn't for -Wunused-local-typedefs Date: Mon, 27 Aug 2012 15:42:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: preprocessor X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: dodji at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dodji at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg01806.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53469 --- Comment #2 from Dodji Seketeli 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