From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664558426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4MHKMWWNqYNq6luPhcQQCCcoaGRShgP2uEoCHyH4FNU=; b=HjKRowz5WuozzV6XLDujpW+Bk/THQboR8YeYY1JTy96L7c7Ssq5qD0YGDBN9REY4Odo24d YlbrO2z4edsaheFNoWC5KEG/tRJL7XeuAy/BswTbJl6Ld/DizXFPF1w8vBkjtTe4Ttwa2j AosC4Ojc8/24xd+82s2TLJ28W2zxBDA= 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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, -- 2.38.0.rc2