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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id CA5C6384607B for ; Thu, 12 Nov 2020 03:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CA5C6384607B 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-540-gMh8pgUTMKGGurXfSWMZpw-1; Wed, 11 Nov 2020 22:04:04 -0500 X-MC-Unique: gMh8pgUTMKGGurXfSWMZpw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2D068015AD for ; Thu, 12 Nov 2020 03:04:03 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (ovpn-117-246.rdu2.redhat.com [10.10.117.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AB1E73672; Thu, 12 Nov 2020 03:04:03 +0000 (UTC) From: Marek Polacek To: GCC Patches Subject: [PATCH] system: Add WARN_UNUSED_RESULT Date: Wed, 11 Nov 2020 22:03:48 -0500 Message-Id: <20201112030348.2939013-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.2 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_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 12 Nov 2020 03:04:09 -0000 I'd like to have the option of marking functions with __attribute__ ((__warn_unused_result__)), so this patch adds a macro. And use it for maybe_wrap_with_location, it's always a bug if the return value is not used, which happened to me and got me confused. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/ChangeLog: * system.h (WARN_UNUSED_RESULT): Define for GCC >= 3.4. * tree.h (maybe_wrap_with_location): Add WARN_UNUSED_RESULT. --- gcc/system.h | 6 ++++++ gcc/tree.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/system.h b/gcc/system.h index b0f3f1dd019..6f6ab616a61 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -789,6 +789,12 @@ extern void fancy_abort (const char *, int, const char *) #define ALWAYS_INLINE inline #endif +#if GCC_VERSION >= 3004 +#define WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) +#else +#define WARN_UNUSED_RESULT +#endif + /* Use gcc_unreachable() to mark unreachable locations (like an unreachable default case of a switch. Do not use gcc_assert(0). */ #if (GCC_VERSION >= 4005) && !ENABLE_ASSERT_CHECKING diff --git a/gcc/tree.h b/gcc/tree.h index 684be10b440..9a713cdb0c7 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1214,7 +1214,7 @@ get_expr_source_range (tree expr) extern void protected_set_expr_location (tree, location_t); extern void protected_set_expr_location_if_unset (tree, location_t); -extern tree maybe_wrap_with_location (tree, location_t); +WARN_UNUSED_RESULT extern tree maybe_wrap_with_location (tree, location_t); extern int suppress_location_wrappers; base-commit: 0f5f9ed5e5a041b636cc002451b1e8b2295f8e4f -- 2.28.0