From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7BAB8385DC1B; Wed, 15 Apr 2020 21:06:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BAB8385DC1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586984805; bh=ZTVtHyS4mkpP/Ayzyy91H0o4R7y4WdZn96Q9r/zgj6A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZkIkUkd4OnK02yrSzJSK1xLIpJLFgsoCU938c2+jTqCgzzBtlGW5fdou7xTj14hlZ kUV+c0BKiZwlWYbKPbC4yVfQGwThSFzpxVAOjTAxAipOYh2+jBccf+Cil96GAn5AYS jvga7cMfqyZNMmMeZVHdDIkLCyB4jcH1+BMcYHuc= From: "jsm28 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/94558] Designated initializer inside _Generic is misinterpreted Date: Wed, 15 Apr 2020 21:06:45 +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: 9.3.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: jsm28 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution bug_status 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 21:06:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94558 Joseph S. Myers changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #1 from Joseph S. Myers --- This is not a bug. First, note that all expressions inside _Generic must satisfy all syntactic= and compile-time constraints and must not involve any compile-time undefined behavior, just like an expression inside "if (0)"; it's simply that only on= e of the expressions ends up being evaluated at runtime when the _Generic expres= sion is executed. So one of the compound literals tries to use an object of type= A to initialize element b of the union, which results in the given error. Next, the error refers to initializing the field _ (i.e. .b._) with an incompatible type rather than to initializing .b with an incompatible type because the rule for initializing subaggregates and contained unions, in the absence of braces, is that an initializer with the correct structure or uni= on type initializes the whole of a contained subaggregate or union, but otherw= ise the initializer goes down into nested subobjects. So when the initializer doesn't match the type of the field named by the designator, or the first f= ield of that field (where an aggregate or union), or the first field of that, recursively, it ends up being interpreted as an initializer for the scalar = at the start of that object; that is, the int at the start of .b. So the error message refers to the type int.=