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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0DAA73858D1E for ; Fri, 30 Sep 2022 17:37:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DAA73858D1E 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=1664559458; 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: in-reply-to:in-reply-to:references:references; bh=B84R42xAc65KHS+tCNjTvW+2Lw6SwFw0wXuUcBAuEps=; b=FZdsI+KD2LPkuXwckWX2/Ilcxej9Rdc9xvlHtLZlpj4KF6giGnK05+laU0sDbpQ0lTIhZ3 X/pObWYl7mhvyECaD1zWc/lQNSQNTHuQX9kjseaE+zrXqFoTv4G38Jf+YkX5/K152FBslR 1ZY0bKJd+x9nnmFm1EL7/TPFwLDBSCk= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-299-G3sJXNieO9-yZVuX0bXXxA-1; Fri, 30 Sep 2022 13:37:37 -0400 X-MC-Unique: G3sJXNieO9-yZVuX0bXXxA-1 Received: by mail-qk1-f198.google.com with SMTP id bk21-20020a05620a1a1500b006be9f844c59so4235999qkb.9 for ; Fri, 30 Sep 2022 10:37:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date; bh=B84R42xAc65KHS+tCNjTvW+2Lw6SwFw0wXuUcBAuEps=; b=kQqX3OwDJJJx2n4XIHqyEWSBN0AkPC/+MhFGF3M62faDE6Sofgixr98KSb9ptER95v Bm4XZv25APkLd9b/QEXc+XN3LC2jae5i5gDiZKkmV0HWjNgiJJxckIsz+PfoaGCslAfd ASOF7zMweYSNy3fxrXmaAq2UAZWPrl4XVhp+vpBimz2HvbcAH9isDoXoSQ45S9v0g/9p ZVz4kaIr/jKHdGNeh4mM+cmu42y7A0vt2W0P62C4ZVc02dyNUamiDb2PkBXnwl3zuK9n UuUTiY7+FVynJQdTQmswL63f+wu9WyUzkUv8V+g84I5vvRsYJ8z8J27M70l0UiqmsELP 7x1g== X-Gm-Message-State: ACrzQf1VSNhhUwgzABAQxZ1u1kD6bxcc90njTcyN4FjCUkXcEU6mm2tr AfS3PGjqyCU0NFlYxBj6W6d6tXqg/iaUSXTF6Ibx4otyxxwVCcrhdS50WBobm0TR9lb4P3B2GMV IUK8Ti0lUrPRc91wpmQ== X-Received: by 2002:a05:620a:2910:b0:6ce:1517:918 with SMTP id m16-20020a05620a291000b006ce15170918mr6841763qkp.190.1664559457114; Fri, 30 Sep 2022 10:37:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+UoZP/VQsr5LigNmxerNskmVCgP0HAIAM2mCOlA4QaOmQ290KIwiOl5oQy8Y3e9vJVxn/XQ== X-Received: by 2002:a05:620a:2910:b0:6ce:1517:918 with SMTP id m16-20020a05620a291000b006ce15170918mr6841741qkp.190.1664559456858; Fri, 30 Sep 2022 10:37:36 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id b19-20020ac86793000000b0035bbb6268e2sm2130905qtp.67.2022.09.30.10.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:37:36 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 30 Sep 2022 13:37:35 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: make some cp_trait_kind switch statements exhaustive In-Reply-To: <20220930172019.1459433-1-ppalka@redhat.com> Message-ID: <5dacc85d-d972-aed1-fac4-a325c5422a50@idea> References: <20220930172019.1459433-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.5 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_LOW,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: On Fri, 30 Sep 2022, Patrick Palka wrote: > 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 Whoops, this should be #undef DEFTRAIT_TYPE > + /* 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 > >