From patchwork Fri Sep 30 17:20:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1684972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Maks3AWV; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfH7Q142tz1ypH for ; Sat, 1 Oct 2022 03:20:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BC0C385C402 for ; Fri, 30 Sep 2022 17:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BC0C385C402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664558446; bh=4MHKMWWNqYNq6luPhcQQCCcoaGRShgP2uEoCHyH4FNU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Maks3AWVeLVVGRGaiItUtEbsyU6xSZ4XtZNOTu5Bxj+eCkDxpwdhOCEEXki7eC48n ANx72YZQxmlpiciPN0Di+U27ClgeTIMysFW2QRp4g+ieXdiQTKZfafHbFzgIls7fUH 68NT6rqzp6MInRDdLW9Oaz6D3usFT2hbTBl8ObAY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3F1133858D1E for ; Fri, 30 Sep 2022 17:20:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F1133858D1E Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-626-DaTfngVVObuSAHi2JNZn3A-1; Fri, 30 Sep 2022 13:20:26 -0400 X-MC-Unique: DaTfngVVObuSAHi2JNZn3A-1 Received: by mail-qt1-f199.google.com with SMTP id fx6-20020a05622a4ac600b0035a70ba1cbcso3410557qtb.21 for ; Fri, 30 Sep 2022 10:20:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=4MHKMWWNqYNq6luPhcQQCCcoaGRShgP2uEoCHyH4FNU=; b=Glaa4saaTdL0rYLc78hmHszI7hKH/NmnZh1zo6IzgXQ9avmsO+w5RqwR8hZTc58yRT zO2naISdtDdOGMz8Rmlj1gtTT4O1JEMOrOx/GGSdGnw0un9Tbggyt/AssFL8cZdhAZGI xGe+MUJ7PsJT5YhCm6E0Dl2xDPrOpCMhpxo9Gj+vwI8v7N8V9lKvbgxlCj3jkfkgvn3+ phzpQ6X/vKBrsv6zyQStydPGMtu5xwabssi+oB8KAOGhfwL7a+4738m+DFoWWUjTvKUw inpKm9LbbeczrSagPMrzZFO6rhaf3iG7dQ0KSrjk5JbDP9tdKH5CqOaPCz2nCJ3bocpE DRqA== X-Gm-Message-State: ACrzQf3x6r5/YQDL+Lqw98Kk0mplh175/YhWnpvo7fL3VcuKCa9NtVyt +EC7k4XTazWIVpBoIOlPuvhrAt4DuYmHkmHTjg7/KeLk7OmvUAfygT9AsK3nYmiQ3ePH3GcEVNp cKRXhd0M3seNGaMjsNFWhr6vIckLm4T+wN0QvIGWIR/Y9LMrD8LAkozva4G6AKi71YcI= X-Received: by 2002:a05:6214:ca1:b0:4aa:a1a1:6503 with SMTP id s1-20020a0562140ca100b004aaa1a16503mr7575204qvs.123.1664558424569; Fri, 30 Sep 2022 10:20:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nJdnlGS/uMFrUABhLBu+tu/M3HAq0wKPpMEchqvqYh9RQeA6qVHqnwOTjcZolPAq1c488Bw== X-Received: by 2002:a05:6214:ca1:b0:4aa:a1a1:6503 with SMTP id s1-20020a0562140ca100b004aaa1a16503mr7575173qvs.123.1664558424277; Fri, 30 Sep 2022 10:20:24 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id gb10-20020a05622a598a00b0035ba366cc90sm2231906qtb.15.2022.09.30.10.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:20:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: make some cp_trait_kind switch statements exhaustive Date: Fri, 30 Sep 2022 13:20:19 -0400 Message-Id: <20220930172019.1459433-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This replaces the unreachable default case in some cp_trait_kind switches with an exhaustive listing of the _unexpected_ trait codes, so that when adding a new trait we'll get a -Wswitch diagnostic if we forget to handle the trait code in one of these switches. Bootstrappend and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * semantics.cc (trait_expr_value): Make cp_trait_kind switch exhaustive. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. --- gcc/cp/semantics.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 66ee2186a84..91ad8aa340f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12052,10 +12052,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_REF_CONVERTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/false); - default: - gcc_unreachable (); - return false; +#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ + case CPTK_##CODE: +#include "cp-trait.def" +#undef DEFTRAIT_EXPR + /* These are handled by finish_trait_type. */ + break; } + + gcc_unreachable (); } /* Returns true if TYPE meets the requirements for the specified KIND, @@ -12204,7 +12209,11 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - default: +#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ + case CPTK_##CODE: +#include "cp-trait.def" +#undef DEFTRAIT_TYPE + /* These are handled by finish_trait_type. */ gcc_unreachable (); } @@ -12250,9 +12259,19 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2) if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); return cv_unqualified (type1); - default: - gcc_unreachable (); + +#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ + case CPTK_##CODE: +#include "cp-trait.def" +#undef DEFTRAIT_EXPR + /* These are handled by finish_trait_expr. */ + case CPTK_BASES: + case CPTK_DIRECT_BASES: + /* These are handled by finish_bases. */ + break; } + + gcc_unreachable (); } /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,