stan-dev / stan-dev/rstan

rstan compilation conflict with class std::auto_ptr

Open
#777 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

rstan compilation conflict with class std::auto_ptr.

Description:

rstan_2.19.3.tar.gz is installed with lots of warning message as below:

In file included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/memory:80,
                 from /software/R/site-library/BH/include/boost/move/algorithm.hpp:33,
                 from /software/R/site-library/BH/include/boost/move/move.hpp:32,
                 from /software/R/site-library/BH/include/boost/variant/detail/move.hpp:28,
                 from /software/R/site-library/BH/include/boost/variant/recursive_wrapper.hpp:17,
                 from /software/R/site-library/BH/include/boost/variant/detail/enable_recursive.hpp:34,
                 from /software/R/site-library/BH/include/boost/variant/recursive_variant.hpp:17,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/node/expression.hpp:4,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/type/bare_expr_type.hpp:4,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/variable_map.hpp:5,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast.hpp:7,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/compiler.hpp:5,
                 from stanc.cpp:22:
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~

In /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/bits/unique_ptr.h, class auto_ptr is defined as template<typename> class auto_ptr;.
In backward/auto_ptr.h which is included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/memory, class auto_ptr is defined twice:

  template<typename _Tp>
    class auto_ptr
    {
    private:
      _Tp* _M_ptr;
      
    public:
      /// The pointed-to type.
      typedef _Tp element_type;
      
      /**
       *  @brief  An %auto_ptr is usually constructed from a raw pointer.
       *  @param  __p  A pointer (defaults to NULL).
       *
       *  This object now @e owns the object pointed to by @a __p.
       */
      explicit
      auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { }

      /**
       *  @brief  An %auto_ptr can be constructed from another %auto_ptr.
       *  @param  __a  Another %auto_ptr of the same type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.
       */
      auto_ptr(auto_ptr& __a) throw() : _M_ptr(__a.release()) { }

      /**
       *  @brief  An %auto_ptr can be constructed from another %auto_ptr.
       *  @param  __a  Another %auto_ptr of a different but related type.
       *
       *  A pointer-to-Tp1 must be convertible to a
       *  pointer-to-Tp/element_type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.
       */
      template<typename _Tp1>
        auto_ptr(auto_ptr<_Tp1>& __a) throw() : _M_ptr(__a.release()) { }

      /**
       *  @brief  %auto_ptr assignment operator.
       *  @param  __a  Another %auto_ptr of the same type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.  The object that this one @e
       *  used to own and track has been deleted.
       */
      auto_ptr&
      operator=(auto_ptr& __a) throw()
      {
	reset(__a.release());
	return *this;
      }

      /**
       *  @brief  %auto_ptr assignment operator.
       *  @param  __a  Another %auto_ptr of a different but related type.
       *
       *  A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.  The object that this one @e
       *  used to own and track has been deleted.
       */
      template<typename _Tp1>
        auto_ptr&
        operator=(auto_ptr<_Tp1>& __a) throw()
        {
	  reset(__a.release());
	  return *this;
	}

      /**
       *  When the %auto_ptr goes out of scope, the object it owns is
       *  deleted.  If it no longer owns anything (i.e., @c get() is
       *  @c NULL), then this has no effect.
       *
       *  The C++ standard says there is supposed to be an empty throw
       *  specification here, but omitting it is standard conforming.  Its
       *  presence can be detected only if _Tp::~_Tp() throws, but this is
       *  prohibited.  [17.4.3.6]/2
       */
      ~auto_ptr() { delete _M_ptr; }
      
      /**
       *  @brief  Smart pointer dereferencing.
       *
       *  If this %auto_ptr no longer owns anything, then this
       *  operation will crash.  (For a smart pointer, <em>no longer owns
       *  anything</em> is the same as being a null pointer, and you know
       *  what happens when you dereference one of those...)
       */
      element_type&
      operator*() const throw() 
      {
	__glibcxx_assert(_M_ptr != 0);
	return *_M_ptr; 
      }
      
      /**
       *  @brief  Smart pointer dereferencing.
       *
       *  This returns the pointer itself, which the language then will
       *  automatically cause to be dereferenced.
       */
      element_type*
      operator->() const throw() 
      {
	__glibcxx_assert(_M_ptr != 0);
	return _M_ptr; 
      }
      
      /**
       *  @brief  Bypassing the smart pointer.
       *  @return  The raw pointer being managed.
       *
       *  You can get a copy of the pointer that this object owns, for
       *  situations such as passing to a function which only accepts
       *  a raw pointer.
       *
       *  @note  This %auto_ptr still owns the memory.
       */
      element_type*
      get() const throw() { return _M_ptr; }
      
      /**
       *  @brief  Bypassing the smart pointer.
       *  @return  The raw pointer being managed.
       *
       *  You can get a copy of the pointer that this object owns, for
       *  situations such as passing to a function which only accepts
       *  a raw pointer.
       *
       *  @note  This %auto_ptr no longer owns the memory.  When this object
       *  goes out of scope, nothing will happen.
       */
      element_type*
      release() throw()
      {
	element_type* __tmp = _M_ptr;
	_M_ptr = 0;
	return __tmp;
      }
      
      /**
       *  @brief  Forcibly deletes the managed object.
       *  @param  __p  A pointer (defaults to NULL).
       *
       *  This object now @e owns the object pointed to by @a __p.  The
       *  previous object has been deleted.
       */
      void
      reset(element_type* __p = 0) throw()
      {
	if (__p != _M_ptr)
	  {
	    delete _M_ptr;
	    _M_ptr = __p;
	  }
      } 

  template<>
    class auto_ptr<void>
    {
    public:
      typedef void element_type;
    } _GLIBCXX_DEPRECATED;
Reproducible Steps:
library(rstan)
model_code <- 'parameters {real y;} model {y ~ normal(0,1);}'
fit <- stan(model_code=model_code)   
mean(extract(fit)$y)   
Current Output:

Failed with warning: 'template class std::auto_ptr' is dep

Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! fileef016a50f67cfc.cpp:6:36: warning: ISO C++11 requires whitespace after the macro name
 #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
                                    ^
In file included from /software/R/site-library/BH/include/boost/smart_ptr/shared_ptr.hpp:28,
                 from /software/R/site-library/BH/include/boost/shared_ptr.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/time_clock.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from /software/R/site-library/rstan/include/rstan/stan_fit.hpp:13,
                 from /software/R/site-library/rstan/include/rstan/rstaninc.hpp:3,
                 from fileef016a50f67cfc.cpp:7:
/software/R/site-library/BH/include/boost/smart_ptr/detail/shared_count.hpp:356:33: warning: 'template<class> class std::auto_ptr' is dep
Calls: stan ... cxxfunctionplus -> <Anonymous> -> cxxfunction -> compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/opt/freeware/lib64/R/bin/R CMD SHLIB fileef016a50f67cfc.cpp 2> fileef016a50f67cfc.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection
Calls: stan -> stan_model -> cxxfunctionplus -> sink
Execution halted.
Expected Output:

How to avoid the conflicted auto_ptr?

RStan Version:

rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)

R Version:

R3.6.1

Operating System:

AIX7.2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the RStan example on AIX 7.2, using the reported R 3.6.1 and rstan 2.19.3 versions. Read the compiler include chain through rstan/stan_fit.hpp, Boost's shared_count.hpp, and the reported C++ standard-library headers. Done means the example compiles without the auto_ptr conflict and produces the expected fit output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, r
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.