Opened 5 years ago

Closed 5 years ago

#13108 closed Bugs (wontfix)

BOOST_STATIC_ASSERT occurs when serializing a class with default constructor explicitly defined

Reported by: nest_kds@… Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

the following code gives an error:

struct myStruct_assert{ 
    myStruct_assert(){}
    int objectId;
};
BOOST_STATIC_ASSERT( boost::serialization::detail::is_default_constructible< myStruct_assert >::value );

error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x> with [ x=false ]'

while the following code produces no error

struct myStruct_noassert{ 
    int objectId;
};
BOOST_STATIC_ASSERT( boost::serialization::detail::is_default_constructible< myStruct_noassert >::value );

Also, in case of

boost::optional< int > objectId;

the error is produced in both cases - with or without default constructor specified

boost libraries are compiled with following parameters:

toolset=msvc-9.0
variant=debug
threading=multi
link=shared/static

BOOST_USE_WINAPI_VERSION=0x0501
_BIND_​TO_CURRENT_VCLIBS_VERSION
BOOST_ALL_DYN_LINK
BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL

Change History (3)

comment:1 by anonymous, 5 years ago

Version: Boost 1.63.0Boost 1.64.0

comment:2 by Richard Hazlewood <boost@…>, 5 years ago

Same issue occurs for g++ 4.6.4 (with -std=c++0x). It looks like boost::serialization::detail::is_default_constructible falls into using boost::has_trivial_constructor; however, it may be that this just does not fully work for these compilers (see docs: http://www.boost.org/doc/libs/1_64_0/libs/type_traits/doc/html/boost_typetraits/reference/has_trivial_constructor.html)

Oddly enough the constructor declared with = default passes on g++ 4.6.4; e.g.
( g++-4.6 -W -Wall -std=c++0x ... )


#include "boost/serialization/detail/is_default_constructible.hpp"

#ifndef BOOST_HAS_TRIVIAL_CONSTRUCTOR
#error
#endif

struct T
{
  T() = default;
};

struct X
{
  X() {}
};

int main(int argc, char *argv[])
{
  (void)argc; (void)argv;

  static_assert(BOOST_HAS_TRIVIAL_CONSTRUCTOR(T), "t fail");
  static_assert(BOOST_HAS_TRIVIAL_CONSTRUCTOR(X), "x fail");
}

boost_htd.cpp:22:3: error: static assertion failed: "x fail"

comment:3 by Robert Ramey, 5 years ago

Resolution: wontfix
Status: newclosed

This is just a limitation of older compilers. The explanation can be found at https://github.com/boostorg/serialization/blob/develop/include/boost/serialization/detail/is_default_constructible.hpp

I'm sorry there is just no way to fix it other than not explicitly defining a default constructor which you shouldn't need to do anyway.

Note: See TracTickets for help on using tickets.