From patchwork Tue Apr 1 17:46:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gutson X-Patchwork-Id: 336094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A22391400D9 for ; Wed, 2 Apr 2014 04:47:04 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; q=dns; s=default; b=LyJQA0TT5jyexZoW6fYRm 3vDXYWkF95Nqs/GG7f6qSK/XaJMmIWKwwo6vxCsJKvCTTHmoJHSVmVpdl0l+3FbE v7BxHGhauOimZm/FTtQWtJ2OQWFZvBWD2aQTy/WNXKqzIy6GvDzLYlt1Wsm7qU8L pKNe0yAjdB1xLDlpBQ4pkk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; s=default; bh=hy0CcP4GeRMNOBlnsxZSTeioja0 =; b=PGsN6Mseh9eOfsOZIV7xqt3MzuzZtaJuNOrzlysVNf75BVoQP5W59Uzof57 5VBY8YOU6/foR6xHF0E18vpY60Jg7xwY3I+styshWlS5x7pSVbfZRYOExQG8Aqi9 0rJZYS6wDDA1KEOPbM+ScOsCxqmrzO2BllkPQpF7k68ywuOM= Received: (qmail 7855 invoked by alias); 1 Apr 2014 17:46:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 7846 invoked by uid 89); 1 Apr 2014 17:46:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mail-la0-f46.google.com Received: from mail-la0-f46.google.com (HELO mail-la0-f46.google.com) (209.85.215.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 01 Apr 2014 17:46:56 +0000 Received: by mail-la0-f46.google.com with SMTP id hr17so7182528lab.5 for ; Tue, 01 Apr 2014 10:46:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=fRc1YAJZHBPwmrGAm42w07HCYYX4aXG8G/VQn5bC2hs=; b=TurNPdUWfiMFOeyUUQg4gp4PRxM3XOI+SQBEqF3EzIftnCl88tErOHOpkIqAqnxPbh mA7Yc8FKnzbbfBJulg0nPjchRgzw+JGBr8Vwic2mHldHj7yQtMsRUnQvdeF9SvamQD/2 vhVjM09sm11HYY002LSwc7/y05vDpIZAb4fQ1OwlYJ/fOxwgfOA0J9dzb892/Rnbw05o E43LFgHZBxI+sbeFcFrmdt3qbommyoXTiEm3Uhk+8ZcqRguaa5jtDFedBvkGLRoX8ZeS 1fJ6bj2bkiQ889hZE7pMIFiOb3lt62iwsTKpTNG4AWrgCDGb2telHE0FytOUKHHMJuQh +yjQ== X-Gm-Message-State: ALoCoQlKf2ZVrERTQixMjlhuR1+wGcnpm/AnPTQjZeQvB4Fr+OcbxjcxntGvuakAH45n7Ul4kDeX MIME-Version: 1.0 X-Received: by 10.152.2.225 with SMTP id 1mr2055619lax.37.1396374413084; Tue, 01 Apr 2014 10:46:53 -0700 (PDT) Received: by 10.112.9.40 with HTTP; Tue, 1 Apr 2014 10:46:52 -0700 (PDT) In-Reply-To: References: Date: Tue, 1 Apr 2014 14:46:52 -0300 Message-ID: Subject: Fwd: [PATCH] pedantic warning behavior when casting void* to ptr-to-func, 4.8 and 4.9 From: Daniel Gutson To: gcc-patches@gcc.gnu.org I just realized I posted the patch in the wrong list. ---------- Forwarded message ---------- From: Daniel Gutson Date: Tue, Apr 1, 2014 at 10:43 AM Subject: [PATCH] pedantic warning behavior when casting void* to ptr-to-func, 4.8 and 4.9 To: gcc Mailing List Hi, I observed two different behaviors in gcc 4.8.2 and 4.9 regarding the same issue, IMO both erroneous. Regarding 4.8.2, #pragma GCC diagnostic ignored "-pedantic" doesn't work in cases such as: void* p = 0; #pragma GCC diagnostic ignored "-pedantic" F* f2 = reinterpret_cast(p); (see testcase in the patch). The attached patch attempts to fix this issue. Since I no longer have write access, please apply this for me if correct (is the 4.8 branch still alive for adding fixes?). Regarding 4.9, gcc fails to complain at all when -pedantic is passed, even specifying -std=c++03. Please let me know if this is truly a bug, in which case I could also fix it for the latest version as well (if so, please let me know if I should look into trunk or any other branch). Thanks, Daniel. 2014-03-31 Daniel Gutson gcc/cp/ * typeck.c (build_reinterpret_cast_1): Pass proper argument to warn() in pedantic. gcc/testsuite/g++.dg/ * diagnostic/pedantic.C: New test case. --- gcc-4.8.2-orig/gcc/cp/typeck.c 2014-03-31 22:29:42.736367936 -0300 +++ gcc-4.8.2/gcc/cp/typeck.c 2014-03-31 14:26:43.536747050 -0300 @@ -6639,7 +6639,7 @@ where possible, and it is necessary in some cases. DR 195 addresses this issue, but as of 2004/10/26 is still in drafting. */ - warning (0, "ISO C++ forbids casting between pointer-to-function and pointer-to-object"); + warning (OPT_Wpedantic, "ISO C++ forbids casting between pointer-to-function and pointer-to-object"); return fold_if_not_in_template (build_nop (type, expr)); } else if (TREE_CODE (type) == VECTOR_TYPE) --- gcc-4.8.2-orig/gcc/testsuite/g++.dg/diagnostic/pedantic.C 1969-12-31 21:00:00.000000000 -0300 +++ gcc-4.8.2/gcc/testsuite/g++.dg/diagnostic/pedantic.C 2014-03-31 17:24:42.532607344 -0300 @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options "-pedantic" } +typedef void F(void); + +void foo() +{ + void* p = 0; + F* f1 = reinterpret_cast(p); // { dg-warning "ISO" } +#pragma GCC diagnostic ignored "-pedantic" + F* f2 = reinterpret_cast(p); +} +