From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1EF7C3858D32; Tue, 2 Apr 2024 19:06:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EF7C3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712084791; bh=dE/D+SM2U8WU7h+E1ij2WAxNT/tBYjyNZ+J+OAhi/qM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jh3an06tuaieW2mN/WnlO/JLdffGtZQKLmi2OZLDwtDQ+Dtn1LHtdkbFq/8cnEwQV wWNI794czYf8DEb+YpzIoV5WllSvljxRX58X8kD9OEf3q7PkR7S5icegNyLKZw+YWG XG2NYdiOGn5ndrjxOs0gRfk3wA9Soy1buqvRUHS0= From: "harald at gigawatt dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114526] ISO C does not prohibit extensions: fix misconception. Date: Tue, 02 Apr 2024 19:06:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: diagnostic, documentation X-Bugzilla-Severity: normal X-Bugzilla-Who: harald at gigawatt dot nl X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114526 --- Comment #16 from Harald van Dijk --- (In reply to Joseph S. Myers from comment #15) > In the cases where there is no statement either way, the behavior is > undefined as a property of the translation unit (not just of the executio= n): > it is not defined whether such a conversion may occur in a translation un= it, This is still not stated anywhere in the standard though. > Being undefined > through omission of definition has, as per clause 4, not difference in > meaning or emphasis from being explicitly undefined. Of course, but if the standard had explicitly stated that conversion between function pointers and object pointers was undefined, it might be phrased in= a way that applies even to dead code. If you are relying on being undefined by omission, you have to be really sure the behaviour is not defined *anywhere= *, including by general rules about dead code. I will grant that the standard never explicitly says dead code is not execu= ted and has no effect, but if this is in dispute, we have a bigger problem. > I'd suggest working with the Undefined Behavior Study Group on making it > more explicit for each instance of undefined behavior whether it is a > property of the program or of an execution thereof, but if any case seems > particularly unclear, filing an issue once the new C standard issue track= er > is up and running would probably be reasonable (but it seems likely that > such issues would be referred to the UB study group to recommend a > resolution just as floating-point issues would likely be referred to the = CFP > group). Considering my stance is that WG14 have repeatedly and consistently stated = what the rules are, I see this as a waste of their time. > It's *not* the case that the same rules apply everywhere, because there a= re > two different kinds of UB depending on whether what's undefined is a > property of the program or an execution thereof. Division by zero is > obviously UB as a property of an execution, because whether a value is ze= ro > is a property of the execution. Considering this example of 1/0 has been the subject of two separate DRs th= at I referenced, I have to say it is not obvious from the standard itself. Keepi= ng in mind that the operands are constants and implementations are required to= be capable of constant expression evaluation in some contexts, a hypothetical standard that permitted, or even required, this to be evaluated at translat= ion time (with undefined behaviour) even in otherwise dead code would make perf= ect sense. But that is not the C standard we have, at least not the official interpretation of it. > Different types for the same identifier with > external linkage in different translation units is obviously UB as a > property of the program (and not widely diagnosed without LTO), as the wh= ole > concept of an identifier corresponding to an object with a particular val= ue > depends on a globally consistent notion of its type and the UB is about > presence of declarations rather than a particular path of execution. Yes, because a program that does not reference these identifiers still viol= ates the rule that specifies they must have compatible type. This means that the= re is no execution of the program that avoids UB. But in my program, there is no rule that is violated. Perhaps the rule that= you describe in your comment, that no program may contain any unsupported conversion anywhere, regardless of whether the conversion is ever performed, should exist, but it is simply not the case that there is such a rule to be found anywhere in the standard. One additional comment, though: The fact that conversions between function pointers and object pointers are rejected under -pedantic-errors mean that 'gcc -std=3Dc99 -pedantic-errors' cannot be used as the implementation for POSIX's c99 utility, as POSIX's c= 99 utility is required to conform to the C99 standard, and simultaneously, per= mit conversions between function pointers and object pointers (at least in some cases). (Adjust for later versions as needed.) This is unfortunate, and regardless of whether the C standard allows such programs to be rejected, c= an we agree that the C standard also allows them to be accepted, and POSIX requires them to be accepted? Is that not already sufficient reason to reconsider?=