Skip to content

Is returning a local instance of BehaviorTreeFactory by value from a function disallowed ? #937

Open
@vincent-hui

Description

@vincent-hui

Describe the bug
This commit e7a3991 makes user code compilation fail if a function that returns a local instance of BehaviorTreeFactory by value is defined.

How to Reproduce*
myheader.h

#include "behaviortree_cpp/bt_factory.h"

inline BT::BehaviorTreeFactory factoryOfBtFactory() {
  BT::BehaviorTreeFactory factory;
  return factory;
}

main.cpp

#include "myheader.h"

int main(){
return 0;
}

Compilation error

/usr/local/include/c++/15.0.1/bits/unique_ptr.h: In instantiation of ‘constexpr void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = BT::BehaviorTreeFactory::PImpl]’:
/usr/local/include/c++/15.0.1/bits/unique_ptr.h:399:17:   required from ‘constexpr std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = BT::BehaviorTreeFactory::PImpl; _Dp = std::default_delete<BT::BehaviorTreeFactory::PImpl>]’
  399 |           get_deleter()(std::move(__ptr));
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/home/vincent/workspace/BehaviorTree.CPP/include/behaviortree_cpp/bt_factory.h:218:3:   required from here
  218 |   BehaviorTreeFactory(BehaviorTreeFactory&& other) noexcept = default;
      |   ^~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/15.0.1/bits/unique_ptr.h:91:23: error: invalid application of ‘sizeof’ to incomplete type ‘BT::BehaviorTreeFactory::PImpl’
   91 |         static_assert(sizeof(_Tp)>0,
      |                       ^~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions