From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94054 invoked by alias); 26 Sep 2016 12:23:54 -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 93999 invoked by uid 89); 26 Sep 2016 12:23:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=3706 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; Mon, 26 Sep 2016 12:23:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 886AB13D17 for ; Mon, 26 Sep 2016 12:23:50 +0000 (UTC) Received: from redhat.com (ovpn-204-20.brq.redhat.com [10.40.204.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8QCNlrv022409 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Sep 2016 08:23:49 -0400 Date: Mon, 26 Sep 2016 12:32:00 -0000 From: Marek Polacek To: GCC Patches Cc: Jason Merrill , Jakub Jelinek Subject: C++ PATCH for __has_cpp_attribute and fallthrough Message-ID: <20160926122346.GH3223@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-09/txt/msg01814.txt.bz2 This patch updates __has_cpp_attribute for fallthrough, which is now supported. The system.h hunk should aid people building trunk GCC with older GCC 7 not supporting this attribute yet. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-09-26 Marek Polacek * c-lex.c (c_common_has_attribute): Handle attribute fallthrough. * system.h: Use __has_attribute to check whether the fallthrough attribute is supported. * g++.dg/cpp1z/feat-cxx1z.C: Test attribute fallthrough. diff --git gcc/c-family/c-lex.c gcc/c-family/c-lex.c index 829c18b..5c6496e 100644 --- gcc/c-family/c-lex.c +++ gcc/c-family/c-lex.c @@ -350,7 +350,8 @@ c_common_has_attribute (cpp_reader *pfile) else if (is_attribute_p ("deprecated", attr_name)) result = 201309; else if (is_attribute_p ("maybe_unused", attr_name) - || is_attribute_p ("nodiscard", attr_name)) + || is_attribute_p ("nodiscard", attr_name) + || is_attribute_p ("fallthrough", attr_name)) result = 201603; if (result) attr_name = NULL_TREE; diff --git gcc/system.h gcc/system.h index 8ca71cf..0952e4f 100644 --- gcc/system.h +++ gcc/system.h @@ -746,8 +746,12 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__)) #endif -#if GCC_VERSION >= 7000 -# define gcc_fallthrough() __attribute__((fallthrough)) +#if GCC_VERSION >= 7000 && defined(__has_attribute) +# if __has_attribute(fallthrough) +# define gcc_fallthrough() __attribute__((fallthrough)) +# else +# define gcc_fallthrough() +# endif #else # define gcc_fallthrough() #endif diff --git gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C index 982572e..71c8c7d 100644 --- gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C +++ gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C @@ -370,6 +370,12 @@ # error "__has_cpp_attribute(nodiscard) != 201603" # endif +# if ! __has_cpp_attribute(fallthrough) +# error "__has_cpp_attribute(fallthrough)" +# elif __has_cpp_attribute(fallthrough) != 201603 +# error "__has_cpp_attribute(fallthrough) != 201603" +# endif + #else # error "__has_cpp_attribute" #endif Marek