From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 32AAC3858D38 for ; Thu, 10 Nov 2022 23:06:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32AAC3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62f.google.com with SMTP id t25so8812677ejb.8 for ; Thu, 10 Nov 2022 15:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cMRSkCy6D3JlY+I2yb5J3s0t+JGwYrGxF5VGCfhsHC4=; b=Kz569MnFurjC6qPPRUy9ktzOjqBz2zOqRlbzERLqbZqIncHAY2HKxDRej/o4t7N92Q dU0ocmkUc6A105CnrHa2mCUQSKeKZ+lWGEUdIfo/K3DnVZ+4dYhk1CU/pFw6s8C0yQ+s 18/z6cjudOStr4h6yvBBvDEIBUtjGSJnU+GTXo1qMZPXLkzsOenQyFj/hcpFGT+0JPMy akIKX0qPW1VOwSzmt/HquY4NojNGZtQDFUzsoq+LI14D0mjixlC2pSBE7R+D2mTEyxmi 9/VZ7smE0PsQBuUExErOyW9K5wxRuEYL7ukZPE9spmYh4/Fl+D93bqqo2vnjk0/J27YL OQxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cMRSkCy6D3JlY+I2yb5J3s0t+JGwYrGxF5VGCfhsHC4=; b=KWbUIfaag/4UCSGz/hpG54QKXm9vwBaZSAqGmnMwagnWgr6X2uGaGThhxLX4WnLUfo O4y2n1TirHYzj7dl/6jbk4RFtEjun51uMdM4kDTcpJZg2Ozd62W72kmSIU2BNMu1m0Qe zUlrIwB9wiOHFTGmyzvc1VPPqXxVweYvEQ+6Gemwsnxg1AIEXNCgXlHYyOHwfr4T8Icz 57DgyQZIf8ph0L/Rni/sOBxRxEJkFIjMH2UlbcPxn3o0A82gPqNZGufqTA7DZWGKcGfc dEw2RmcTznWf3NvqP/Q0Uka7u1WDLxXZDDQi6MO/vOTCHbb4hTnewM1AbAFcfe6gU063 Gb5Q== X-Gm-Message-State: ACrzQf3LPkEPXaQg0VqJHmIMxBX/lsef/svZsKHGX+Flg7QMkiDtW+8R tCFzTLGakPCvRrlPeZxP7ck3scLDH2WL5HutW6s= X-Google-Smtp-Source: AMsMyM7tV0KDSieL7m0CaDOdZEn6+utf69aAIJvM/hkJ3DDH2SptfRTGFoLli6SKulVUK65AZuwEyW9t9ZGdYIi5grY= X-Received: by 2002:a17:906:1da9:b0:7ad:9892:921a with SMTP id u9-20020a1709061da900b007ad9892921amr4088194ejh.506.1668121563769; Thu, 10 Nov 2022 15:06:03 -0800 (PST) MIME-Version: 1.0 References: <87mt8ysm3y.fsf@oldenburg.str.redhat.com> <87h6z6sjqp.fsf@oldenburg.str.redhat.com> In-Reply-To: <87h6z6sjqp.fsf@oldenburg.str.redhat.com> From: Jonathan Wakely Date: Thu, 10 Nov 2022 23:05:52 +0000 Message-ID: Subject: Re: -Wint-conversion, -Wincompatible-pointer-types, -Wpointer-sign: Are they hiding constraint C violations? To: Florian Weimer Cc: Marek Polacek , gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 10 Nov 2022 at 19:17, Florian Weimer via Gcc wrote: > > * Marek Polacek: > > > On Thu, Nov 10, 2022 at 07:25:21PM +0100, Florian Weimer via Gcc wrote: > >> GCC accepts various conversions between pointers and ints and different > >> types of pointers by default, issuing a warning. > >> > >> I've been reading the (hopefully) relevant partso f the C99 standard, > >> and it seems to me that C implementations are actually required to > >> diagnose errors in these cases because they are constraint violations: > >> the types are not compatible. > > > > It doesn't need to be a hard error, a warning is a diagnostic message, > > which is enough to diagnose a violation of any syntax rule or > > constraint. > > > > IIRC, the only case where the compiler _must_ emit a hard error is for > > #error. > > Hmm, you could be right. > > The standard says that constraint violations are not undefiend behavior, > but of course it does not define what happens in the presence of a > constraint violation. So the behavior is undefined by omission. This > seems to be a contradiction. As long as a diagnostic is issued, the invalid program can be successfully translated. Presumably the implementation defines what it means in that case, because it's not a valid C program, so the standard no longer applies. As you say, that's undefined by omission. > I assumed that there was a rule similar to the the rule for #error for > any kind of diagnostic, which would mean that GCC errors are diagnostic > messages in the sense of the standard, but GCC warnings are not. > > I wonder how C++ handles this. Similarly. We don't have constraint violations, we have "diagnosable rules", see [intro.compliance.general]. If a program contains a violation of a diagnosable rule, the implementation must issue a diagnostic message. What it does after that is up to the implementation, the program has left the realm of valid C++ code. It's not exactly easy for a user to know whether a given compiler warning was issued because of a constraint (or diagnosable rule) violation, or because e.g. the compiler thinks extra parens or more consistent indentation would be a good idea. In the former case, the program has undefined behaviour (strictly speaking, but in practice the implementation might "define" its behaviour) and in the latter case it doesn't. -pedantic-errors can help, as that turns the former class into errors.