From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 7628B3858D38; Sat, 1 Oct 2022 16:23:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7628B3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664641383; bh=ry0QjdAn3m+mnJ+BNfgDWlmAgJ70a4KYM8R0MmjRr9o=; h=From:To:Subject:Date:From; b=Iak+/j3y0UMRG/GhxTzOS5ZwrJ5AOMSHgKQFXJgGm8SaIqve3FQMeVkzgmSIiAiUI 2NCemrOwygtgbceT350X1jRILOk04QDm5CRt3O/bAY7LlUgbZKi4lZivB5PjBmKtKF 0O4eR9rX69FgdtrR3Y6ZaOl4m8BQHAXD7d4/zgdM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3013] c++: make some cp_trait_kind switch statements exhaustive X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: ca01d2526917ec6e54b30472d3aedfd46d4ca585 X-Git-Newrev: c051060ade8a4392bbd4604a551a8dcb8c937f45 Message-Id: <20221001162303.7628B3858D38@sourceware.org> Date: Sat, 1 Oct 2022 16:23:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c051060ade8a4392bbd4604a551a8dcb8c937f45 commit r13-3013-gc051060ade8a4392bbd4604a551a8dcb8c937f45 Author: Patrick Palka Date: Sat Oct 1 12:21:36 2022 -0400 c++: make some cp_trait_kind switch statements exhaustive This replaces the unreachable default case in some cp_trait_kind switches with an exhaustive listing of the trait codes that we don't expect to see, so that when adding a new trait we'll get a helpful -Wswitch warning if we forget to handle the new trait in a relevant switch. gcc/cp/ChangeLog: * semantics.cc (trait_expr_value): Make cp_trait_kind switch statement exhaustive. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. Diff: --- 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..4fb0675cca9 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_TYPE + /* Type-yielding traits are handled in 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 + /* Type-yielding traits are handled in 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 + /* Expression-yielding traits are handled in finish_trait_expr. */ + case CPTK_BASES: + case CPTK_DIRECT_BASES: + /* BASES and DIRECT_BASES are handled in finish_bases. */ + break; } + + gcc_unreachable (); } /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,