Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9153 closed Bugs (fixed)

Building boost::log in Sun Studio 12.3: boost::log::aux::light_function fails to build

Reported by: Brian Vandenberg <phantall+boost@…> Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc: phantall+boost@…

Description

I get an error building boost::log in Sun Studio 12.3, while building anything that uses light_function_pp.hpp:

"./boost/log/detail/light_function_pp.hpp", line 44: Error: Multiple declaration for impl.
"./boost/log/expressions/filter.hpp", line 58:     Where: While specializing "boost::log::v2_mt_posix::aux::light_function<bool(const boost::log::v2_mt_posix::attribute_value_set&)>".
"./boost/log/expressions/filter.hpp", line 58:     Where: Specialized in non-template code.

I can reproduce this problem on a much smaller scale:

template < typename SignatureT >
class light_function ;

template < typename ResultT, typename ArgT0 >
class light_function < ResultT ( ArgT0 ) > {
private:
  struct impl_base {};
  impl_base *m_pImpl;

#if defined( BREAK_IT )
  template < typename FunT >
  class impl;
  template < typename FunT >
  friend class impl;
#endif

  template < typename FunT >
  class impl : public impl_base {};

#if !defined( BREAK_IT )
  template < typename FunT >
  friend class impl;
#endif

public:
  template <typename T>
  light_function( T const &t ) : m_pImpl( static_cast<impl_base*)new impl<T>() ) {}
};

int main( int argc, char *argv[] ) {
  light_function<bool(int&)> lf(3);

  return 0;
}

When compiled in Linux or Solaris with SS12.3, I get the exact same error.

Change History (9)

comment:1 by Brian Vandenberg <phantall+boost@…>, 9 years ago

I forgot to mention, though I hope it's obvious: compile with -DBREAK_IT to see the problem.

comment:2 by Brian Vandenberg <phantall+boost@…>, 9 years ago

As for the 'why' of this, I'm not really sure. The attribute_set and attribute_value_set classes (among others) use this idiom of forward declaring a class before marking it as a friend class.

I tried using some compiler options to force it to only use explicitly specialized versions of the class and the error wouldn't go away.

comment:3 by Andrey Semashev, 9 years ago

Unfortunately, I don't have access to this compiler, neither there are testers using it in the test farm. So the only way I can fix this is if you provide a patch or through some experiments to figure out the source of the problem.

Could you try to move impl definition out of light_function body?

comment:4 by Brian Vandenberg <phantall+boost@…>, 9 years ago

Andy,

If you remove the forward declaration for impl and move the friend statement to after the impl body, the error goes away.

comment:5 by Brian Vandenberg <phantall+boost@…>, 9 years ago

Cc: phantall+boost@… added

comment:6 by Andrey Semashev, 9 years ago

Does it help if you just define BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS macro?

comment:7 by Brian Vandenberg <phantall+boost@…>, 9 years ago

Yes.

comment:8 by Andrey Semashev, 9 years ago

Resolution: fixed
Status: newclosed

(In [85873]) Disabled friend declarations for nested class templates for SunPro compiler. Fixes #9153.

comment:9 by Brian Vandenberg <phantall+boost@…>, 9 years ago

Andy,

I haven't found a download link for it, but back in 2008 they began releasing 'express' versions of the compiler suite. It may be possible to get an express version for the current sun studio compiler.

Note: See TracTickets for help on using tickets.