[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 14:27:29 PDT 2017


jyu2 added inline comments.


================
Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:27
+}
+
+struct N : A {
----------------
aaron.ballman wrote:
> jyu2 wrote:
> > 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.
> Good point! A test case with `noexcept(false)` would be handy as would one where `~ShouldDiagnose()` is marked `noexcept(true)` explicitly rather than picking up the `noexcept(false)` implicitly.
Okay I add two tests ShouldDiagnoes and ShouldNotDiagnoes. 


https://reviews.llvm.org/D33333





More information about the cfe-commits mailing list