From patchwork Fri Oct 11 20:23:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1175556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510808-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QylQrT+B"; dkim-atps=neutral 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 46qfYH11Bhz9sCJ for ; Sat, 12 Oct 2019 07:23:46 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=XPtGHLwz468oT8NaUIJr/VQ+OqYfi1aUgDjs+g9ZGN22IktndaJCj 4DDAIl8DUJT32/e1uca7ZWsfsY95iPbhLQ9jgCQ4cVf0IEfMQxKx7HbNTUwgwkSF J90PzZ1MCj5o/oc+TreOngFCjLHdcmexVKzeebQlyOEXXKh+FQoDz0= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=tg7V0EYOCRne0Uu49Fd7GE7FXG0=; b=QylQrT+BRZbzmXSM/7iG jZO22TXPhME1Z1s9P1syt87XuTfSiWd/0hl9M7rZESswZdTa1oaATtCauCHL8W29 CMMmGar5qwXvCiLrrcVvttvkQM4bLF3FmDFvLx476yC/ZCkDeCsgsVfEg/2+Wr9i QQFbFfKKSd1HTWkoRecdes4= Received: (qmail 19217 invoked by alias); 11 Oct 2019 20:23:39 -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 19205 invoked by uid 89); 11 Oct 2019 20:23:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Oct 2019 20:23:38 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 101FF307D847 for ; Fri, 11 Oct 2019 20:23:37 +0000 (UTC) Received: from redhat.com (ovpn-121-75.rdu2.redhat.com [10.10.121.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 879214535; Fri, 11 Oct 2019 20:23:36 +0000 (UTC) Date: Fri, 11 Oct 2019 16:23:34 -0400 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/92062 - ODR-use ignored for static member of class template Message-ID: <20191011202334.GT2949@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) has_value_dependent_address wasn't stripping location wrappers so it gave the wrong answer for "&x" in the static_assert. That led us to thinking that the expression isn't instantiation-dependent, and we skipped static initialization of A<0>::x. This patch adds stripping so that has_value_dependent_address gives the same answer as it used to before the location wrappers addition. Bootstrapped/regtested on x86_64-linux, ok for trunk and 9? 2019-10-11 Marek Polacek PR c++/92062 - ODR-use ignored for static member of class template. * pt.c (has_value_dependent_address): Strip location wrappers. * g++.dg/cpp0x/constexpr-odr1.C: New test. * g++.dg/cpp0x/constexpr-odr2.C: New test. diff --git gcc/cp/pt.c gcc/cp/pt.c index 84464436991..521d0c56002 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -6542,6 +6542,8 @@ check_valid_ptrmem_cst_expr (tree type, tree expr, static bool has_value_dependent_address (tree op) { + STRIP_ANY_LOCATION_WRAPPER (op); + /* We could use get_inner_reference here, but there's no need; this is only relevant for template non-type arguments, which can only be expressed as &id-expression. */ diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C new file mode 100644 index 00000000000..cf3f95f0565 --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C @@ -0,0 +1,19 @@ +// PR c++/92062 - ODR-use ignored for static member of class template. +// { dg-do run { target c++11 } } + +template struct A { + static const bool x; + static_assert(&x, ""); // odr-uses A<...>::x +}; + +int g; + +template +const bool A::x = (g = 42, false); + +void f(A<0>) {} // A<0> must be complete, so is instantiated +int main() +{ + if (g != 42) + __builtin_abort (); +} diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C new file mode 100644 index 00000000000..0927488e569 --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C @@ -0,0 +1,19 @@ +// PR c++/92062 - ODR-use ignored for static member of class template. +// { dg-do run { target c++11 } } + +template struct A { + static const bool x; + enum { force_instantiation =! &x}; // odr-uses A<...>::x +}; + +int g; + +template +const bool A::x = (g = 42, false); + +void f(A<0>) {} // A<0> must be complete, so is instantiated +int main() +{ + if (g != 42) + __builtin_abort (); +}