Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #172

Re: Defect Report: implicitly declared member function, noexcept or throw(), ambiguous.

From Yakov Galka <ybungalobill@gmail.com>
Newsgroups comp.std.c++
Subject Re: Defect Report: implicitly declared member function, noexcept or throw(), ambiguous.
Date 2011-06-23 13:46 -0600
Organization http://groups.google.com
Message-ID <bf7b410e-b7c8-4bd1-8c4f-ffb468cf6597@d26g2000prn.googlegroups.com> (permalink)
References <cff819e2-6b6d-4b97-9018-38e6cfde613e@e7g2000vbw.googlegroups.com> <843e1996-3a69-4d09-8874-734b60fdd80e@j23g2000yqc.googlegroups.com>

Show all headers | View raw


On Jun 22, 5:22 pm, Daniel Krügler <daniel.krueg...@googlemail.com>
wrote:
> On 2011-06-22 09:30, Yakov Galka wrote:
>
>
> > N3290, "15.4 Exception specifications [except.spec], (14)" says:
>
> > An implicitly declared special member function (Clause 12) shall have
> > an exception-specification. If f is
> > an implicitly declared default constructor, copy constructor, move
> > constructor, destructor, copy assignment
> > operator, or move assignment operator, its implicit exception-
> > specification specifies the type-id T if and only
> > if T is allowed by the exception-specification of a function directly
> > invoked by f s implicit definition; f shall
> > allow all exceptions if any function it directly invokes allows all
> > exceptions, and f shall allow no exceptions
> > if every function it directly invokes allows no exceptions.
>
> > If it happens to allow no exceptions, should it be semantically
> > equivalent to a dynamic-exception-specification and call
> > std::unexpected, or to noexept(true) and call std::terminate directly?
>
> > It does matter in the following case:
>
> > struct X { ~X() { throw 0; } };
>
> > Here, according to "12.4 Destructors [class.dtor]", the above
> > paragraph applies. So ~X gets a non-throwing exception-specification.
>
> > struct X { ~X() noexcept { throw 0; } };
> > struct X { ~X() throw() { throw 0; } };
>
> > Which one?
>
> This has already been reported at earlier occasions, search e.g. for the
> thread "DR: How do implicit exception declarations (dis)allow
> exceptions?" in this group and has already been forwarded to the core
> working group.
>
> Thanks & Greetings from Bremen,
>
> - Daniel Kr gler

Ohh, I'm sorry. I've searched for "Defect Report" and couldn't find
anything relevant because it starts with "DR".

On Jun 22, 5:23 pm, Andrzej Krzemieński <akrze...@gmail.com> wrote:
> On Jun 22, 9:30 am, Yakov Galka <ybungalob...@gmail.com> wrote:
>
> > N3290, "15.4 Exception specifications [except.spec], (14)" says:
>
> > An implicitly declared special member function (Clause 12) shall have
> > an exception-specification. If f is
> > an implicitly declared default constructor, copy constructor, move
> > constructor, destructor, copy assignment
> > operator, or move assignment operator, its implicit exception-
> > specification specifies the type-id T if and only
> > if T is allowed by the exception-specification of a function directly
> > invoked by f s implicit definition; f shall
> > allow all exceptions if any function it directly invokes allows all
> > exceptions, and f shall allow no exceptions
> > if every function it directly invokes allows no exceptions.
>
> > If it happens to allow no exceptions, should it be semantically
> > equivalent to a dynamic-exception-specification and call
> > std::unexpected, or to noexept(true) and call std::terminate directly?
>
> > It does matter in the following case:
>
> > struct X { ~X() { throw 0; } };
>
> > Here, according to "12.4 Destructors [class.dtor]", the above
> > paragraph applies. So ~X gets a non-throwing exception-specification.
>
> > struct X { ~X() noexcept { throw 0; } };
> > struct X { ~X() throw() { throw 0; } };
>
> > Which one?
>
> Hi, the paragraph you quote only says about implicitly generated
> member functions. Note that for implicitly generated member functions
> two observations apply:
> 1. When compiler (rather than programmer) detects that the member
> function does not throw, it really does not throw (there is no way
> std::terminate or std::unexpected is called due to violated noexcept
> or throw() ).
> 2. Implicitly generated functions do not have bodies, so your examples
> (with a throw in the function body) do not apply to this paragraph.
>
> Also note that noexcept(true) and throw() are compatible in the sense
> that:
> 1. noexcept operator will work the same for either
> 2. the "nothrow" traits like std::is_nothrow_move_constructible will
> work the same for either
>
> (I described it in my article:http://akrzemi1.wordpress.com/2011/06/10/using-noexcept/)
>
> So, whatever the compiler chooses for implicitly generated member
> functions, you will not be able to tell the difference. Thus, under
> the as-if rule, compiler is anyway allowed to switch between the two
> at random, and therefore specifying which one it should choose is not
> necessary.
>
> Regards,
> &rzej
>

There is one (and only one) exception to what you said, "12.4
Destructors [class.dtor]":

A declaration of a destructor that does not have an exception-
specification is implicitly considered to have the same exception-
specification as an implicit declaration (15.4).

--
Yakov Galka


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

Defect Report: implicitly declared member function, noexcept or  throw(), ambiguous. Yakov Galka <ybungalobill@gmail.com> - 2011-06-22 01:30 -0600
  Re: Defect Report: implicitly declared member function, noexcept or  throw(), ambiguous. Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-06-22 08:22 -0600
  Re: Defect Report: implicitly declared member function, noexcept or   throw(), ambiguous. Andrzej Krzemieński <akrzemi1@gmail.com> - 2011-06-22 08:23 -0600
    Re: Defect Report: implicitly declared member function, noexcept or  throw(), ambiguous. Yakov Galka <ybungalobill@gmail.com> - 2011-06-23 13:46 -0600

csiph-web