public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/54722] New: std::is_nothrow_default_constructible<T>::value depends on whether destructor throws or not.
@ 2012-09-26 22:56 cassio.neri at gmail dot com
  2012-09-26 23:14 ` [Bug libstdc++/54722] " paolo.carlini at oracle dot com
  0 siblings, 1 reply; 2+ messages in thread
From: cassio.neri at gmail dot com @ 2012-09-26 22:56 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54722

             Bug #: 54722
           Summary: std::is_nothrow_default_constructible<T>::value
                    depends on whether destructor throws or not.
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: cassio.neri@gmail.com


Consider:

#include <iostream>
#include <type_traits>

struct foo {
  foo() noexcept {}
  ~foo() {}
};

int main() {
  std::cout << std::boolalpha;
  std::cout << std::is_nothrow_default_constructible<foo>::value << std::endl;
  return 0;
}

This should output 'true' but it outputs 'false'. Adding a 'noexcept'
specification to ~foo() makes the code to output the expected result.

Looking at the source, I guess, the reason lies on the implementation of this
helper class:

template<typename _Tp>
  struct __is_nt_default_constructible_atom
  : public integral_constant<bool, noexcept(_Tp())>
  { };

Indeed, the expression '_Tp()' if executed creates a temporary of type _Tp
whose lifetime ends immediately and ~Tp_ is called. Therefore,
'noexcept(_Tp())' is 'true' if and only if neither the constructor nor the
destructor throw.

I believe the below implementation fixes the problem (at least it does for the
example above):

template<typename _Tp>
  struct __is_nt_default_constructible_atom
  : public std::integral_constant<bool, noexcept(new (std::nothrow) _Tp)>
  { };


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/54722] std::is_nothrow_default_constructible<T>::value depends on whether destructor throws or not.
  2012-09-26 22:56 [Bug libstdc++/54722] New: std::is_nothrow_default_constructible<T>::value depends on whether destructor throws or not cassio.neri at gmail dot com
@ 2012-09-26 23:14 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 2+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-26 23:14 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54722

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|cassio.neri at gmail dot    |
                   |com                         |
         Resolution|                            |DUPLICATE

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-26 23:13:59 UTC ---
Dup.

*** This bug has been marked as a duplicate of bug 51452 ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-26 23:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-26 22:56 [Bug libstdc++/54722] New: std::is_nothrow_default_constructible<T>::value depends on whether destructor throws or not cassio.neri at gmail dot com
2012-09-26 23:14 ` [Bug libstdc++/54722] " paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).