From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123815 invoked by alias); 16 Jul 2019 12:40:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 123804 invoked by uid 89); 16 Jul 2019 12:40:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 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= 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; Tue, 16 Jul 2019 12:40:06 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F8BF3082B4B; Tue, 16 Jul 2019 12:40:05 +0000 (UTC) Received: from redhat.com (ovpn-125-86.rdu2.redhat.com [10.10.125.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D809A5C257; Tue, 16 Jul 2019 12:40:00 +0000 (UTC) Date: Tue, 16 Jul 2019 12:42:00 -0000 From: Marek Polacek To: Matthew Beliveau Cc: Jason Merrill , gcc-patches@gcc.gnu.org, Joseph Myers Subject: Re: [C++ PATCH] PR c++/90590 Suppress warning for enumeration value not handled in switch warning Message-ID: <20190716123958.GD3469@redhat.com> References: <20190712183859.GQ5989@redhat.com> <20190712224930.GT5989@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) X-SW-Source: 2019-07/txt/msg01116.txt.bz2 On Mon, Jul 15, 2019 at 09:47:26AM -0400, Matthew Beliveau wrote: > Okay I kept the TYPE_MAIN_VARIANT and dropped the accidental new line! > Hopefully this should be fine! CCing Joseph as this is c-family/ stuff. > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2019-07-12 Matthew Beliveau > > PR c++/90590 > * c-warn.c (c_do_switch_warnings): Suppress warning for enumerators > with reserved names that are in a system header. > > * c-c++-common/pr90590-1.c: New test. > * c-c++-common/pr90590-1.h: New test. > * c-c++-common/pr90590-2.c: New test. > * c-c++-common/pr90590-2.h: New test. > > diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c > index b5d09e761d7..51c54a283e5 100644 > --- gcc/c-family/c-warn.c > +++ gcc/c-family/c-warn.c > @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see > #include "gcc-rich-location.h" > #include "gimplify.h" > #include "c-family/c-indentation.h" > +#include "c-family/c-spellcheck.h" > #include "calls.h" > #include "stor-layout.h" > > @@ -1628,6 +1629,15 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location, > if (cond && tree_int_cst_compare (cond, value)) > continue; > > + /* If the enumerator is defined in a system header and uses a reserved > + name, then we continue to avoid throwing a warning. */ > + location_t loc = DECL_SOURCE_LOCATION > + (TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type))); > + if (in_system_header_at (loc) > + && name_reserved_for_implementation_p > + (IDENTIFIER_POINTER (TREE_PURPOSE (chain)))) > + continue; > + > /* If there is a default_node, the only relevant option is > Wswitch-enum. Otherwise, if both are enabled then we prefer > to warn using -Wswitch because -Wswitch is enabled by -Wall > diff --git gcc/testsuite/c-c++-common/pr90590-1.c gcc/testsuite/c-c++-common/pr90590-1.c > new file mode 100644 > index 00000000000..4e11debb7fa > --- /dev/null > +++ gcc/testsuite/c-c++-common/pr90590-1.c > @@ -0,0 +1,15 @@ > +// PR c++/90590 > +// { dg-options -Wswitch } > +#include "pr90590-1.h" > + > +void > +g () > +{ > + enum E e = _A; > + switch (e) // { dg-bogus "enumeration value '_C' not handled in switch" } > + { > + case _A: > + case _B: > + break; > + } > +} > diff --git gcc/testsuite/c-c++-common/pr90590-1.h gcc/testsuite/c-c++-common/pr90590-1.h > new file mode 100644 > index 00000000000..22f1a7d5d52 > --- /dev/null > +++ gcc/testsuite/c-c++-common/pr90590-1.h > @@ -0,0 +1,2 @@ > +#pragma GCC system_header > +enum E { _A, _B, _C }; > diff --git gcc/testsuite/c-c++-common/pr90590-2.c gcc/testsuite/c-c++-common/pr90590-2.c > new file mode 100644 > index 00000000000..23da97f9d74 > --- /dev/null > +++ gcc/testsuite/c-c++-common/pr90590-2.c > @@ -0,0 +1,11 @@ > +// PR c++/90590 > +// { dg-options -Wswitch } > + > +#include "pr90590-2.h" > + > +void > +fn () > +{ > + switch (c.b) // { dg-bogus "enumeration value" } > + ; > +} > diff --git gcc/testsuite/c-c++-common/pr90590-2.h gcc/testsuite/c-c++-common/pr90590-2.h > new file mode 100644 > index 00000000000..e4f8635576f > --- /dev/null > +++ gcc/testsuite/c-c++-common/pr90590-2.h > @@ -0,0 +1,4 @@ > +#pragma GCC system_header > +struct { > + enum { _A } b; > +} c; Marek