From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9CDE93844072; Tue, 18 Aug 2020 14:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CDE93844072 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597761968; bh=8CaKIHostbHlDi1c3EEgGcPBf1E3Ju+eHfSNhqQWEJ8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=u0y2z8p6REMSwTcNLUdDdcwc0MRbOrB3Q5goxp5Z4kX3YU5GV9OINHyhKaM5Ji5+1 vSyHuGW1txIRgbCwUw3UPsh8FQzh8xLdNiXd2FNvedsaW4bpWXDI4CC8IgW4aLq8qM nXZy/f/GniKwtQjnNyNstEbluvSmgnNYOGWCvIrk= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/61372] Add warning to detect noexcept functions that might throw Date: Tue, 18 Aug 2020 14:46:08 +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: 4.9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org 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: 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: Tue, 18 Aug 2020 14:46:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61372 --- Comment #4 from Jonathan Wakely --- (In reply to David Crocker from comment #3) > (In reply to Jonathan Wakely from comment #2) > > extern "C" functions can throw, so it would be wrong to unconditionally > > assume they can't. >=20 > True, you can write an extern "C" function that throws. But does it ever > make sense to? I don't think so. Functions written in C and then declared > extern "C" in a C++ program so that they can be called from C++ won't thr= ow > or propagate exceptions, That's not true. std::bsearch and std::qsort are counterexamples. You don't know what the user-provided function does, and you can't assume it doesn't throw. > even if they end up calling functions written in > C++ that throw. The only reason to write a function in C++ and declare it > extern "C" is so that it call be called from C, in which case it had bett= er > not throw. That's an incorrect assumption. Not all extern "C" functions are written in C++. Even if they are, you can't assume they don't throw because they could= use callbacks that can throw, or they might throw even in C programs (which wor= ks fine for some targets, unwinding the stack exactly as a C++ program wants it to). It would be OK to optionally assume functions with C language linkage don't throw, but it must be optional.=