From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 6C1E23858027 for ; Mon, 22 Aug 2022 17:33:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C1E23858027 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 27MHW4FE013568; Mon, 22 Aug 2022 12:32:04 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 27MHW3ak013565; Mon, 22 Aug 2022 12:32:03 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 22 Aug 2022 12:32:03 -0500 From: Segher Boessenkool To: Andrea Bocci Cc: gcc-help@gcc.gnu.org Subject: Re: Warn about conversion from floating point to integers Message-ID: <20220822173203.GP25951@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2022 17:33:09 -0000 Hi! On Sat, Aug 20, 2022 at 11:21:50AM +0200, Andrea Bocci wrote: > is there a way to ask GCC to produce a warning when there is a conversion > from a floating point type (float or double) to an integer type (char, > short, int, long, etc.), but not when there is a conversion from double to > float ? > > The reason is that we often do computations in double precision and store > the result in single precision, so I'd rather not warn about that. > > -Wconversion warns about both kinds and more. > -Wfloat-conversion warns about both kinds. There is no separate option. But, you can just grep the error messages? fc.c: In function 'f': fc.c:1:28: warning: conversion from 'double' to 'float' may change value [-Wfloat-conversion] 1 | float f(double x) { return x; } | ^ fc.c: In function 'g': fc.c:2:26: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion] 2 | int g(double x) { return x; } | ^ Not ideal of course, but this should be workable? (You may want to set LANG=C to get parsable warning messages). If you want a separate -W option for this, please file a PR? See . Thanks! Segher