From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF9C8385DC0A; Tue, 16 Jun 2020 05:12:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF9C8385DC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592284343; bh=Gd4nq8lP3wxWKZN7Wk33xm0eVr/lCyDtjw+wEael1JY=; h=From:To:Subject:Date:From; b=AkfPe+iYWuoxmuHGXdiHz6wziFzffhqx9FtIZfiwqi16+PWYXUwOSOgPHbdrUiYwL 8nOPCwuCC+DJYOdG49+YSdDFEWoasbbyKPbYXl+ZUCZ8xAABwKjZITB6qEMbhf5Sp4 b4ToyMIzygPIWXdk4W4Bl2zi+zTbZqUSWMQok2YE= From: "gcc-90 at tbilles dot hu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95693] New: Incorrect error from undefined behavior sanitizer Date: Tue, 16 Jun 2020 05:12:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc-90 at tbilles dot hu X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Tue, 16 Jun 2020 05:12:24 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95693 Bug ID: 95693 Summary: Incorrect error from undefined behavior sanitizer Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc-90 at tbilles dot hu Target Milestone: --- After upgrading GCC from 7.2 to 10.1 I get a runtime error when using -fsanitize=3Dundefined. I cannot see anything wrong with the code. It was a= lso suggested on the gcc-help mailing list that this is a bug in the compiler. (https://gcc.gnu.org/pipermail/gcc-help/2020-June/139055.html) The code in question can be found on Compiler Explorer (also pasted at the = end of this description): https://godbolt.org/z/7rAxJj It shows that different compiler versions behave differently. Version 10.1 prints "runtime error: reference binding to null pointer of ty= pe 'int'" although there is no null pointer in the code, the reference is boun= d to a global integer. There is a comment on line 16 that explicitly defaults the Derived construc= tor. If you switch the comment with line 17, both compiler versions run fine wit= hout producing the runtime error although the defaulted constructor should be exactly the same the user defined one: https://godbolt.org/z/UShm-u According to Compiler Explorer the incorrect behavior began in GCC 8.x seri= es and is still present in trunk. --- int global =3D 9; class Payload { public: Payload() : data(global) {} private: int& data; }; struct Base { Payload payload; }; class Derived : public Base { public: //Derived() =3D default; Derived() : Base() {} Payload p; }; int main() { Derived t; }=