From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59342 invoked by alias); 6 Jun 2019 12:19:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 59304 invoked by uid 89); 6 Jun 2019 12:19:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=U*redi 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; Thu, 06 Jun 2019 12:19:23 +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 7395AB5C1B; Thu, 6 Jun 2019 12:19:15 +0000 (UTC) Received: from localhost (unknown [10.33.36.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBFAA2DE85; Thu, 6 Jun 2019 12:19:12 +0000 (UTC) Date: Thu, 06 Jun 2019 12:19:00 -0000 From: Jonathan Wakely To: Antony Polukhin Cc: libstdc++ , gcc-patches List Subject: Re: [PATCH] PR libstdc++/71579 assert that type traits are not misused with an incomplete type Message-ID: <20190606121912.GP2599@redhat.com> References: <20190508211032.GD2599@redhat.com> <20190530163808.GP2599@redhat.com> <20190531103550.GV2599@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="K9FID0tFm7ImS7zj" Content-Disposition: inline In-Reply-To: <20190531103550.GV2599@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) X-SW-Source: 2019-06/txt/msg00340.txt.bz2 --K9FID0tFm7ImS7zj Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 701 On 31/05/19 11:35 +0100, Jonathan Wakely wrote: >On 31/05/19 08:58 +0300, Antony Polukhin wrote: >>On Thu, May 30, 2019, 19:38 Jonathan Wakely wrote: >><...> >> >>>I've attached a relative diff, to be applied on top of yours, with my >>>suggested tweaks. Do you see any issues with it? >>> >>>(If you're happy with those tweaks I can go ahead and apply this, >>>there's no need for an updated patch from you). >>> >> >>Looks good. Please apply! > >Here's what I've tested and committed to trunk. > >I decided to add a more detailed changelog too. I'm removing some of these assertions again, because they are either reundant or wrong. Tested x86_64-linux, committed to trunk. --K9FID0tFm7ImS7zj Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 8483 commit 6ffe4cf371688563be1680ffb75cc1160540cf2e Author: redi Date: Thu Jun 6 12:13:47 2019 +0000 Remove redundant static assertions in [meta.unary.prop] traits The type property predicates that are implemented by a compiler builtin already do the right checks in the compiler. The checks for complete type or unbounded arrays were wrong for these types anyway. * include/std/type_traits (is_empty, is_polymorphic, is_final) (is_abstract, is_aggregate): Remove static_assert. * testsuite/20_util/is_abstract/incomplete_neg.cc: Check for error from builtin only. * testsuite/20_util/is_aggregate/incomplete_neg.cc: Likewise. Add missing -std=gnu++17 option. * testsuite/20_util/is_empty/incomplete_neg.cc: New test. * testsuite/20_util/is_final/incomplete_neg.cc: New test. * testsuite/20_util/is_polymorphic/incomplete_neg.cc: Check for error from builtin only. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272000 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 78a113af415..e53d3c8d535 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -746,19 +746,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_empty : public integral_constant - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; + { }; /// is_polymorphic template struct is_polymorphic : public integral_constant - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; + { }; #if __cplusplus >= 201402L #define __cpp_lib_is_final 201402L @@ -766,20 +760,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_final : public integral_constant - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; + { }; #endif /// is_abstract template struct is_abstract : public integral_constant - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; + { }; template::value> @@ -3174,10 +3162,7 @@ template template struct is_aggregate : bool_constant<__is_aggregate(remove_cv_t<_Tp>)> - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; + { }; /// is_aggregate_v template diff --git a/libstdc++-v3/testsuite/20_util/is_abstract/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_abstract/incomplete_neg.cc index 94f4ecd6000..a2a73d01a06 100644 --- a/libstdc++-v3/testsuite/20_util/is_abstract/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_abstract/incomplete_neg.cc @@ -1,7 +1,5 @@ // { dg-do compile { target c++11 } } -// { dg-prune-output "invalid use of incomplete type" } -// { dg-prune-output "must be a complete" } -// + // Copyright (C) 2019 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -19,6 +17,9 @@ // with this library; see the file COPYING3. If not see // . +// Expect the compiler builtin to do the completeness check. +// { dg-error "incomplete type" "" { target *-*-* } 0 } + #include class X; diff --git a/libstdc++-v3/testsuite/20_util/is_aggregate/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_aggregate/incomplete_neg.cc index 8a3dd551cbb..eff3f64c476 100644 --- a/libstdc++-v3/testsuite/20_util/is_aggregate/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_aggregate/incomplete_neg.cc @@ -1,5 +1,6 @@ +// { dg-options "-std=gnu++17" } // { dg-do compile { target c++17 } } -// + // Copyright (C) 2019 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -17,7 +18,8 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "must be a complete class" "" { target *-*-* } 0 } +// Expect the compiler builtin to do the completeness check. +// { dg-error "incomplete type" "" { target *-*-* } 0 } #include diff --git a/libstdc++-v3/testsuite/20_util/is_empty/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_empty/incomplete_neg.cc new file mode 100644 index 00000000000..3bacefbab7e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_empty/incomplete_neg.cc @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// Expect the compiler builtin to do the completeness check. +// { dg-error "incomplete type" "" { target *-*-* } 0 } + +#include + +class X; + +void test01() +{ + std::is_empty(); // { dg-error "required from here" } +} diff --git a/libstdc++-v3/testsuite/20_util/is_final/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_final/incomplete_neg.cc new file mode 100644 index 00000000000..0727c090a83 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_final/incomplete_neg.cc @@ -0,0 +1,30 @@ +// { dg-do compile { target c++14 } } + +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// Expect the compiler builtin to do the completeness check. +// { dg-error "incomplete type" "" { target *-*-* } 0 } + +#include + +class X; + +void test01() +{ + std::is_final(); // { dg-error "required from here" } +} diff --git a/libstdc++-v3/testsuite/20_util/is_polymorphic/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_polymorphic/incomplete_neg.cc index 8cd1b402a41..618c4fa7a9a 100644 --- a/libstdc++-v3/testsuite/20_util/is_polymorphic/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_polymorphic/incomplete_neg.cc @@ -1,7 +1,5 @@ // { dg-do compile { target c++11 } } -// { dg-prune-output "invalid use of incomplete type" } -// { dg-prune-output "must be a complete" } -// + // Copyright (C) 2019 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -19,6 +17,9 @@ // with this library; see the file COPYING3. If not see // . +// Expect the compiler builtin to do the completeness check. +// { dg-error "incomplete type" "" { target *-*-* } 0 } + #include class X; --K9FID0tFm7ImS7zj--