[PATCH] D33333: Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier

Jennifer Yu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 16 13:56:18 PDT 2017


jyu2 added inline comments.


================
Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:1
+// RUN: %clang_cc1 %s  -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fsyntax-only -Wexceptions -verify -std=c++11
+struct A {
----------------
aaron.ballman wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > Please drop the svn auto props.
> > This does not appear to be done.
> This file still has the svn auto props.
I am so sorry.  Remove it.


================
Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:1
+// RUN: %clang_cc1 %s  -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fsyntax-only -Wexceptions -verify -std=c++11
+struct A {
----------------
aaron.ballman wrote:
> rnk wrote:
> > aaron.ballman wrote:
> > > I believe you can drop the -fcxx-exceptions as it should be implied by -fexceptions.
> > It isn't at the -cc1 level, you need -fcxx-exceptions there. -fexceptions controls landingpad cleanup emission.
> Ah, thank you Reid, I forgot about that.
I can remove -fexceptions, since I only care for syntax.


================
Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:27
+}
+
+struct N : A {
----------------
aaron.ballman wrote:
> Can you add a test case like:
> ```
> struct Throws {
>   ~Throws() noexcept(false);
> };
> 
> struct ShouldDiagnose {
>   Throws T;
>   ~ShouldDiagnose() {}
> };
> ```
> I would expect `~ShouldDiagnose()` to be diagnosed as allowing exceptions to escape because of the destructor for `Throws`.
In C++11, destructors are implicitly throw() unless any member or base of the type has a destructor with a different exception specification.

In the case of:
struct Throws {
  ~Throws() noexcept(false);
};

struct ShouldDiagnose {
  Throws T;
  ~ShouldDiagnose() {}
};

You should not see diagnose for   ~ShouldDiagnose() , since   ShouldDiagnose has a member ofr Throws which has destructor with noexcept(false); therefor
  ~ShouldDiagnose has  noexcept(false).

But I add test case which remove (false) part.


https://reviews.llvm.org/D33333





More information about the cfe-commits mailing list