From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D1D243856DFD; Wed, 4 May 2022 16:11:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1D243856DFD From: "jason at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96765] Base class constructor cast to derived should cause a warning Date: Wed, 04 May 2022 16:11:09 +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: 10.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jason at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: 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: cc 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, 04 May 2022 16:11:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96765 Jason Merrill changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #2 from Jason Merrill --- Hmm, is the cast undefined, actually? I thought you were right, but now ca= n't find any wording to that effect. I see [expr.static.cast] If the prvalue of type =E2=80=9Cpointer to cv1 B=E2=80= =9D points to a B that is actually a base class subobject of an object of type D, the resulting pointer points to the enclosing object of type D. Otherwise, the behavior is undefined. But this B is a base of a D. Then [class.cdtor] For an object with a non-trivial constructor, referring to any non-static member or base class of the object before the constructor begins execution results in undefined behavior. but D() has begun execution. Then [class.cdtor] During the construction of an object, if the value of the obj= ect or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor=E2=80=99s this pointer, the va= lue of the object or subobject thus obtained is unspecified. but 'this' in the Base ctor seems to count as obtained indirectly from 'thi= s' in the Derived ctor. Then [class.cdtor] paragraph 4 talks about virtual functions, which this is not. What rule makes this undefined?=