Re: [Boost-bugs] [Boost C++ Libraries] #5637: use of mpl::print imposes default constructible requirement on argument

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5637: use of mpl::print imposes default constructible requirement on argument
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-07-13 18:55:48


#5637: use of mpl::print imposes default constructible requirement on argument
-------------------------------+--------------------------------------------
  Reporter: ramey | Owner: dave
      Type: Tasks | Status: closed
 Milestone: To Be Determined | Component: mpl
   Version: Boost 1.46.1 | Severity: Problem
Resolution: invalid | Keywords: mpl print
-------------------------------+--------------------------------------------
Changes (by dave):

  * status: new => closed
  * resolution: => invalid

Comment:

 Replying to [ticket:5637 ramey]:
> I'm using the following to debug some TMP code that looks like the
 following.
> {{{
> #include <boost/mpl/print.hpp>
> struct X {
> X(int);
> };
>
> boost::mpl::print<
> X
> >::type x;
>
> boost::mpl::print<
> X
> >::type y;
> }}}
>
> I get an error message that the type X is not default constructible.

 I don't think mpl::print is supposed to guarantee you can do that. Why
 don't you just do

 {{{
 boost::mpl::print<X> y;
 }}}

 instead?


> A little investigation yields the definition of mpl::print (simplified
 for exposition)
>
> {{{
> template <class T>
> struct print : identity<T>
> {
> enum { n = sizeof(T) + -1 };
> };
> }}}
>
> So invoking the print creates an instance with the default constructor

 No. Even if you treat `mpl::print` as a metafunction, invoking it doesn't
 create an instance. Constructing an instance of its result… creates an an
 instance (which is of course tautological, sorry).

> which provokes the error in this case. For my purposes, I made the
 following change which seems to address the problem:
>
> {{{
> template <class T>
> struct print : identity<T *>
> {
> enum { n = sizeof(T) + -1 };
> };
> }}}
>
> I'm using MSVC 9.0.

 Unfortunately, `mpl::print` [#1900 is undocumented], but the intention is
 that as a metafunction, it returns `T`, not `T*`, so that change wouldn't
 work.

> A couple of misceleanous issues besides this:
>
> On my current version of GCC - 4.3.4 I get no warning at all.

 If you can figure out how to generate an appropriate warning for that
 compiler, we'd love to have a patch.

> If the same type is printed more than once, I only get the warning on
 the first instance.

 Nothing we can do about the latter; it's just an artifact of your
 compiler's behavior.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5637#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC