Opened 7 years ago

Closed 7 years ago

#11324 closed Bugs (fixed)

has_nothrow_default_constructor incorrectly returns true

Reported by: anonymous Owned by: John Maddock
Milestone: To Be Determined Component: type_traits
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc: akrzemi1@…

Description

The following test program reports errors on the newly added SunOS testers oracle-intel-S2-stlport4 and oracle-sparc-S2-stlport4:

#include <boost/type_traits/has_nothrow_constructor.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>

namespace some_namespace
{
  class base_class
  {
  public:
    base_class & operator=(const base_class &){ throw int(); }
    virtual ~base_class() {}
  };

  class class_without_default_ctor : public base_class
  {
  public:
    char data;
    explicit class_without_default_ctor(char arg) : data(arg) {}
  };
}

int main()
{
  BOOST_TEST_TRAIT_FALSE((boost::has_nothrow_default_constructor<some_namespace::class_without_default_ctor>));
  return boost::report_errors();
}

Change History (8)

comment:1 by John Maddock, 7 years ago

Works for me on msvc and gcc, I assume this is the Oracle C++ compiler?

comment:2 by John Maddock, 7 years ago

Cc: akrzemi1@… added

This is an issue in the compiler intrinsics oracle_has_trivial_constructor and oracle_has_nothrow_constructor both of which report true for class_without_default_ctor.

There is a fix, but it requires adding a new trait is_default_constructible so this may not happen right away.

comment:3 by John Maddock, 7 years ago

Forgot to mention - the fix I have in mind can only be made to work in C++11 land - so would not be applicable for Oracle-stlport which is rather antiquated these days :(

comment:4 by akrzemi1, 7 years ago

For me, the acceptable minimum solution is that the enclosed test case is added to the regression test matrix (and can be marked as expected failure). This way I can see that the root of the problem goes to TypeTraits library.

comment:6 by akrzemi1, 7 years ago

One note. the ideal implementation would correctly detect when a type T has a default noexcept constructor or not. The minimum correct implementation can just always return false. Currently, there are situations where it returns true for types without default constructor. Only implementing the minimum would be an improvement.

comment:7 by John Maddock, 7 years ago

Nod. I will get to this as part of the migration to the "version 2" type traits.

comment:8 by John Maddock, 7 years ago

Resolution: fixed
Status: newclosed

This should now be fixed in develop.

Note: See TracTickets for help on using tickets.