From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9F94A3858D32; Sun, 8 Oct 2023 17:42:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F94A3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696786927; bh=xu5VnBiGsAbYwcY4Xc1ynIYZWWmxsOrFgyGU9E2WmiI=; h=From:To:Subject:Date:From; b=J07axnG1Oy6HQUWbdlH3VTyjBx6HLC5uB1UN9TDflZjLOrA0evPsyoCts9xnTv8cJ tB2M2jrfefzRLne9Rb0IS/ZDGHCIPfnGmLTmGSQ1esfowr/jql1BuyK7o3RXUyvsjH as7NTpi5X56sGWT43bHNtOTCwMLlDumDVgZ/ORNI= From: "llvm at rifkin dot dev" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/111729] New: Design considerations for operator<<(basic_ostream&, const charT*) Date: Sun, 08 Oct 2023 17:42:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: llvm at rifkin dot dev 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111729 Bug ID: 111729 Summary: Design considerations for operator<<(basic_ostream&, const charT*) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: llvm at rifkin dot dev Target Milestone: --- The following program violates a precondition specified in the standard and= is UB however it leads to some surprising behavior #include int main() { std::cout<<(const char*)nullptr; std::cout<<"test"; } There is no segfault, no abort, no non-zero exit status, and no exception. Instead the program silently continues with the output stream's badbit set. This can silently ruin the behavior of the rest of the program leaving the programmer to pull their hair out over what on earth is happening. Yes, it's UB and the programmer can't expect anything, however it's a very = easy mistake to make and the current behavior makes tracking down that mistake exceedingly difficult. I would like to humbly suggest that any of the following behaviors would be better: Segfaulting, throwing an exception, aborting, an assertion failure = in debug, or printing "(null)" (which is the %s behavior). Libc++ and msvc's s= tl both segfault here.=