From patchwork Thu Jul 21 05:55:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 650979 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 3rw30m5Qnrz9sdg for ; Thu, 21 Jul 2016 15:55:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=sqnWVks3; dkim-atps=neutral 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=pTZcon5pKPwaBJg1hwWkLL+Bq55wMuGruyBNZxcrpWBMtk m14n6PfkG5IxeJRAZkmZp/sfif8/usyiiVQdNJEISaoRNULKbWbe+jircTPGUIF3 OhpSQ7wLlAo4TG8qsZII+iJIVmMh3GeIzyOXMPJmLH4xvMAoTcfGcK1wuoA5s= 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:from:date:message-id:subject:to:content-type; s= default; bh=8ft+AmOAfYvKZgbDZ0HL+CTXqDU=; b=sqnWVks30aOl+/tnBm0b t71qpoRUzNdptyqivSXIrnfPjvaugeUGBFAUSin7COQGUIMLGbFfjNVvH6FE+jJN g7WLc5o6soDuSNaDUXZYdURtfHLebHSpGn8oESTueRsrCxyi8Li7Kt7JpvSnrwaZ J6Zro3JfUllWOJC7v0URQoI= Received: (qmail 3972 invoked by alias); 21 Jul 2016 05:55:27 -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 3931 invoked by uid 89); 21 Jul 2016 05:55:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=mbr, Hx-languages-length:2162, xxx X-HELO: mail-oi0-f52.google.com Received: from mail-oi0-f52.google.com (HELO mail-oi0-f52.google.com) (209.85.218.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 21 Jul 2016 05:55:24 +0000 Received: by mail-oi0-f52.google.com with SMTP id j185so103229985oih.0 for ; Wed, 20 Jul 2016 22:55:24 -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:from:date:message-id:subject:to; bh=N4omrwGw+xjbW3vLB4v0cai+ls8oI6KBvhW0DU+FIxc=; b=c9108nepE08Xcl4wpFzOgNSjsGVM8FYBOGtcGfA28PDtnGD49F8ldEGlI+aud913zC rJez2jWeDfAMSXCk+cC5aaJwxSJCUOx3s0BHJ3NVzBg0pZPX8/g3Q9hDQYkUeVkanV4r L2bIH1Iknrtq6uDzsTYH88DHQGWRIRVv6AyctTXdCu0Yq9fpzidAL45qxdqfTIZkS5C8 ZzE8i9Yn56n/i3Mqz+VhNotoZLwSoQtuu4aaOft9E+yL1bNAhvKK3HSQyzPmFjIOSSDO gvthqCzXJU5fJ7o+OKhJqSAIwTpJpQ+iyelaSpMWelLoeQnFnggs721EhJ0tF++450/9 57tQ== X-Gm-Message-State: ALyK8tJV5XuZLhDxVc1e8+csXIknsObY/1gIXd9C1G26y/jwADIcYyxke3sGPglgmxm9vtBBbsevyyHTVB6i/1y/ X-Received: by 10.202.85.85 with SMTP id j82mr15516524oib.150.1469080522556; Wed, 20 Jul 2016 22:55:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.105.169 with HTTP; Wed, 20 Jul 2016 22:55:02 -0700 (PDT) From: Jason Merrill Date: Thu, 21 Jul 2016 01:55:02 -0400 Message-ID: Subject: C++ PATCH for C++/71121 (wrong -Waddress warning with PMF and constexpr) To: gcc-patches List X-IsSubscribed: yes The problem here was that the code that tries to prevent the -Waddress warning used cp_fully_fold, and later code used maybe_constant_value, and the latter simplified the operand more so that it exposed the ADDR_EXPR to the -Waddress warning. Fixed by calling maybe_constant_value from cp_fully_fold. Tested x86_64-pc-linux-gnu, applying to trunk. commit 16703ee40f25fc3afab05b4d25741eb27ce70825 Author: Jason Merrill Date: Wed Jul 20 13:10:40 2016 -0400 PR c++/71121 - -Waddress, constexpr, and PMFs. * cp-gimplify.c (cp_fully_fold): First call maybe_constant_value. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 41ab35f..ee28ba5 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1954,6 +1954,11 @@ cxx_omp_disregard_value_expr (tree decl, bool shared) tree cp_fully_fold (tree x) { + if (processing_template_decl) + return x; + /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't + have to call both. */ + x = maybe_constant_value (x); return cp_fold (x); } diff --git a/gcc/testsuite/g++.dg/warn/Waddress-4.C b/gcc/testsuite/g++.dg/warn/Waddress-4.C new file mode 100644 index 0000000..a9fdfc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Waddress-4.C @@ -0,0 +1,15 @@ +// PR c++/71121 +// { dg-do compile { target c++14 } } +// { dg-options -Waddress } + +struct CC { void mbr(); }; + +constexpr auto getFunc() { + return &CC::mbr; +} + +constexpr bool xxx(void (CC::*_a)()) +{ + constexpr auto f = getFunc(); + return (f == _a); +} diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-7.C b/gcc/testsuite/g++.dg/warn/overflow-warn-7.C deleted file mode 100644 index b536563..0000000 --- a/gcc/testsuite/g++.dg/warn/overflow-warn-7.C +++ /dev/null @@ -1,17 +0,0 @@ -// PR c/62096 - unexpected warning overflow in implicit constant conversion -// { dg-do compile { target c++11 } } - -enum E { - E_val = 1, -}; - -inline constexpr E operator~(E e) -{ - return E(~static_cast(e)); -} - -int main() -{ - int val = ~E_val; // { dg-bogus "overflow in implicit constant conversion" } - (void) val; -}