From patchwork Wed Jun 12 14:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1114605 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-502839-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="hFmSDVxZ"; 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 45P9016NQ8z9s1c for ; Thu, 13 Jun 2019 00:55:13 +1000 (AEST) 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=Rm8YR6kqTWyTsjftq/lD6JllGwzrmecvDw+rENVko7185wphhdGJq RZb3LUw3Tya2wndt0H71nKr2+nmpmUlyhWJTHiaeEgkcGqhHHz5aLDFtvDpKy5BB Ylcsc+H3HHNHj5N2QhUkNmwkKo56vSNtAog8NIZAIeRs9rr7xLxFt8= 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=9/j5lP1tO0BPruE5+y0kE7gvxtU=; b=hFmSDVxZ6BtafCwUh558 797H2TOSn+QQk47SpKhgPD5si5M4O2Ktya8CdLWhUfHJdMqmMfQvscz7GSDxfbOj knFp60BtyhbvKk1/7QhYSFcvmAtIoSPJyBujo2ZKeklZs7klBX9xizbpcL5DV0qM TCORJkwNLa7SwSS3ZBbaCVU= Received: (qmail 9454 invoked by alias); 12 Jun 2019 14:55:06 -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 9437 invoked by uid 89); 12 Jun 2019 14:55:06 -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, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=becoming, __ptr 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; Wed, 12 Jun 2019 14:55:04 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF99C3082201; Wed, 12 Jun 2019 14:55:03 +0000 (UTC) Received: from localhost (unknown [10.33.36.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C32E7C0AF; Wed, 12 Jun 2019 14:55:03 +0000 (UTC) Date: Wed, 12 Jun 2019 15:55:02 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Improve static_assert messages for std::variant Message-ID: <20190612145502.GA27338@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) Also fix a warning with -Wunused-parameter -Wsystem-headers. * include/std/variant (get, get, get_if, get_if) (variant::emplace): Change static_assert messages from "should be" to "must be". (hash::operator()): Remove name of unused parameter. Tested x86_64-linux, committed to trunk. commit 387a4a81a220a86a0a23753041191f0fef93f2da Author: redi Date: Wed Jun 12 14:52:09 2019 +0000 Improve static_assert messages for std::variant Also fix a warning with -Wunused-parameter -Wsystem-headers. * include/std/variant (get, get, get_if, get_if) (variant::emplace): Change static_assert messages from "should be" to "must be". (hash::operator()): Remove name of unused parameter. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272188 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 60472b4c799..c86b0c8ccf3 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -1074,7 +1074,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(__v); } @@ -1083,7 +1083,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>( std::move(__v)); } @@ -1093,7 +1093,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(__v); } @@ -1102,7 +1102,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>( std::move(__v)); } @@ -1113,8 +1113,8 @@ namespace __variant { using _Alternative_type = variant_alternative_t<_Np, variant<_Types...>>; static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); - static_assert(!is_void_v<_Alternative_type>, "_Tp should not be void"); + "The index must be in [0, number of alternatives)"); + static_assert(!is_void_v<_Alternative_type>, "_Tp must not be void"); if (__ptr && __ptr->index() == _Np) return std::addressof(__detail::__variant::__get<_Np>(*__ptr)); return nullptr; @@ -1127,8 +1127,8 @@ namespace __variant { using _Alternative_type = variant_alternative_t<_Np, variant<_Types...>>; static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); - static_assert(!is_void_v<_Alternative_type>, "_Tp should not be void"); + "The index must be in [0, number of alternatives)"); + static_assert(!is_void_v<_Alternative_type>, "_Tp must not be void"); if (__ptr && __ptr->index() == _Np) return std::addressof(__detail::__variant::__get<_Np>(*__ptr)); return nullptr; @@ -1140,7 +1140,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get_if<__detail::__variant::__index_of_v<_Tp, _Types...>>( __ptr); } @@ -1151,7 +1151,7 @@ namespace __variant { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T must occur exactly once in alternatives"); - static_assert(!is_void_v<_Tp>, "_Tp should not be void"); + static_assert(!is_void_v<_Tp>, "_Tp must not be void"); return std::get_if<__detail::__variant::__index_of_v<_Tp, _Types...>>( __ptr); } @@ -1421,7 +1421,7 @@ namespace __variant emplace(_Args&&... __args) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); using type = variant_alternative_t<_Np, variant>; // Provide the strong exception-safety guarantee when possible, // to avoid becoming valueless. @@ -1474,7 +1474,7 @@ namespace __variant emplace(initializer_list<_Up> __il, _Args&&... __args) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); using type = variant_alternative_t<_Np, variant>; // Provide the strong exception-safety guarantee when possible, // to avoid becoming valueless. @@ -1602,7 +1602,7 @@ namespace __variant get(variant<_Types...>& __v) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); if (__v.index() != _Np) __throw_bad_variant_access(__v.valueless_by_exception()); return __detail::__variant::__get<_Np>(__v); @@ -1613,7 +1613,7 @@ namespace __variant get(variant<_Types...>&& __v) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); if (__v.index() != _Np) __throw_bad_variant_access(__v.valueless_by_exception()); return __detail::__variant::__get<_Np>(std::move(__v)); @@ -1624,7 +1624,7 @@ namespace __variant get(const variant<_Types...>& __v) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); if (__v.index() != _Np) __throw_bad_variant_access(__v.valueless_by_exception()); return __detail::__variant::__get<_Np>(__v); @@ -1635,7 +1635,7 @@ namespace __variant get(const variant<_Types...>&& __v) { static_assert(_Np < sizeof...(_Types), - "The index should be in [0, number of alternatives)"); + "The index must be in [0, number of alternatives)"); if (__v.index() != _Np) __throw_bad_variant_access(__v.valueless_by_exception()); return __detail::__variant::__get<_Np>(std::move(__v)); @@ -1730,7 +1730,7 @@ namespace __variant using argument_type [[__deprecated__]] = monostate; size_t - operator()(const monostate& __t) const noexcept + operator()(const monostate&) const noexcept { constexpr size_t __magic_monostate_hash = -7777; return __magic_monostate_hash;