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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id AC5A0384781C for ; Tue, 20 Jul 2021 22:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC5A0384781C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-MZ3KSpHgNYqJVsbJy9dLBA-1; Tue, 20 Jul 2021 18:01:34 -0400 X-MC-Unique: MZ3KSpHgNYqJVsbJy9dLBA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF45D80431E for ; Tue, 20 Jul 2021 22:01:32 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (ovpn-115-201.rdu2.redhat.com [10.10.115.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id B65B760583 for ; Tue, 20 Jul 2021 22:01:32 +0000 (UTC) From: Marek Polacek To: GCC Patches Subject: [PATCH] include: Fix -Wundef warnings in ansidecl.h Date: Tue, 20 Jul 2021 18:01:29 -0400 Message-Id: <20210720220129.198727-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.8 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jul 2021 22:01:37 -0000 This quashes -Wundef warnings in ansidecl.h when compiled in C or C++. In C, __cpp_constexpr and __cplusplus aren't defined so we evaluate them to 0; conversely, __STDC_VERSION__ is not defined in C++. This has caused grief when -Wundef is used with -Werror. I've also tested -traditional-cpp. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? include/ChangeLog: * ansidecl.h: Check if __cplusplus is defined before checking the value of __cpp_constexpr and __cplusplus. Don't check __STDC_VERSION__ in C++. --- include/ansidecl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ansidecl.h b/include/ansidecl.h index 0515228f325..2efe3e85e59 100644 --- a/include/ansidecl.h +++ b/include/ansidecl.h @@ -79,7 +79,7 @@ So instead we use the macro below and test it against specific values. */ /* inline requires special treatment; it's in C99, and GCC >=2.7 supports it too, but it's not in C89. */ #undef inline -#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__)) +#if (!defined(__cplusplus) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__)) /* it's a keyword */ #else # if GCC_VERSION >= 2007 @@ -356,7 +356,7 @@ So instead we use the macro below and test it against specific values. */ #define ENUM_BITFIELD(TYPE) unsigned int #endif -#if __cpp_constexpr >= 200704 +#if defined(__cplusplus) && __cpp_constexpr >= 200704 #define CONSTEXPR constexpr #else #define CONSTEXPR @@ -419,7 +419,7 @@ So instead we use the macro below and test it against specific values. */ so that most attempts at copy are caught at compile-time. */ -#if __cplusplus >= 201103 +#if defined(__cplusplus) && __cplusplus >= 201103 #define DISABLE_COPY_AND_ASSIGN(TYPE) \ TYPE (const TYPE&) = delete; \ void operator= (const TYPE &) = delete base-commit: 4eea703e7d87b1e0b116c93782cab82c9b1e842a -- 2.31.1