Boost C++ Libraries: Ticket #9201: CopyConstructible, as a side effect, requires the type to be DefaultConstructible. https://svn.boost.org/trac10/ticket/9201 <p> The last line in the code bellow (i.e. 'TT b;') in fact requires the TT type to be <a class="missing wiki">DefaultConstructible</a>. In my opinion that is not desired. I think that this bug is present also for other concepts (e.g. Assignable). </p> <p> </p> <pre class="wiki"> BOOST_concept(CopyConstructible,(TT)) { BOOST_CONCEPT_USAGE(CopyConstructible) { TT a(b); // require copy constructor TT* ptr = &amp;a; // require address of operator const_constraints(a); ignore_unused_variable_warning(ptr); } private: void const_constraints(const TT&amp; a) { TT c(a); // require const copy constructor const TT* ptr = &amp;a; // require const address of operator ignore_unused_variable_warning(c); ignore_unused_variable_warning(ptr); } TT b; }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9201 Trac 1.4.3 acharles Tue, 18 Feb 2014 12:37:14 GMT <link>https://svn.boost.org/trac10/ticket/9201#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:1</guid> <description> <p> I think the only way to fix this is to have the following approach: </p> <pre class="wiki"> TT* b_ptr = NULL; if (b_ptr) { TT&amp; b = *b_ptr; TT a(b); // Though I wonder if this shouldn't require an implicit copy constructor. TT* ptr = &amp;a; ... } </pre><p> This is the only way I can think of to create an object of type TT without relying on default construction, while also not invoking undefined behavior and also having it require compilation. </p> <p> Is there a better idea? </p> </description> <category>Ticket</category> </item> <item> <author>Jeremy W. Murphy <jeremy.william.murphy@…></author> <pubDate>Fri, 03 Apr 2015 08:34:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:2</guid> <description> <p> It's an astute observation but I think it's a reasonable requirement and, given the requirements of <a class="missing wiki">CopyConstructible</a>, not a bug. It requires that both </p> <pre class="wiki">T(v) </pre><p> <em>and</em> </p> <pre class="wiki">T u = v; </pre><p> be valid expressions. You can't assign to an object that is not already constructed. </p> </description> <category>Ticket</category> </item> <item> <author>david@…</author> <pubDate>Fri, 03 Apr 2015 12:23:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:3</guid> <description> <p> <code>T u = v;</code> </p> <p> involves default construction and copy assignment, i.e. requires implementation of the <em>default constructor</em> </p> <p> <code>T()</code> </p> <p> and <em>copy assignment operator</em> </p> <p> <code>T &amp;operator=(const T&amp;)</code> </p> <p> Copy construction is implemented using <em>copy constructor</em> with signature </p> <p> <code>T(const T &amp;)</code> </p> <p> My astute observation is: <a class="missing wiki">DefaultConstructible</a>, <a class="missing wiki">CopyConstructible</a> or <a class="missing wiki">CopyAssignable</a> do correspond to the fact whether class implements <em>default constructor</em>, <em>copy constructor</em> or <em>assignment operator</em>. </p> <p> As, on the level of the language, you can implement or not implement any of these 3 members independently on the presence of the implementation of the other 2, so I don't see a reason why there should be some dependencies on the level of the concepts. </p> <p> It would be better to have a quotation from the standard rather than <em>astute observations</em> but my possibilities to quote do not go beyond sites like cppreference.com. </p> <p> Personally I like to create classes that are always initialized with a constructor with arguments and I forbid the default constructor in order to avoid existence of uninitialized objects. That's how I bumped into this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 03 Apr 2015 15:06:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:4</guid> <description> <p> Did you actually test this bug or did you just get it by looking at the code? The implementation of BOOST_CONCEPT_ASSERT is smart enough to avoid requiring the default constructor. It uses a trick similar to acharles' comment. I tested it with both gcc and msvc and it seems to work. </p> <p> <code>T u = v;</code> only requires the copy constructor. It does not do copy assignment. </p> </description> <category>Ticket</category> </item> <item> <author>david@…</author> <pubDate>Fri, 03 Apr 2015 15:43:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:5</guid> <description> <p> Yes, I did. And you did test it or are you just looking at the code? If you did, so maybe this issue can be closed. Note, that it was created 14 months ago, maybe it was addressed since then. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 03 Apr 2015 16:03:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:6</guid> <description> <p> The code hasn't changed. I did test it, on more than one compiler. </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/concept_check.hpp&gt;</span><span class="cp"></span> <span class="k">struct</span> <span class="n">no_default</span> <span class="p">{</span> <span class="n">no_default</span><span class="p">(</span><span class="k">const</span> <span class="n">no_default</span><span class="o">&amp;</span><span class="p">)</span> <span class="p">{}</span> <span class="p">};</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">BOOST_CONCEPT_ASSERT</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">CopyConstructible</span><span class="o">&lt;</span><span class="n">no_default</span><span class="o">&gt;</span><span class="p">));</span> <span class="p">}</span> </pre></div></div><p> Did you use BOOST_CONCEPT_ASSERT or something else? </p> <p> It will definitely fail if you try any variation of: </p> <pre class="wiki">CopyConstructible&lt;T&gt;(); </pre><p> but that's incorrect usage. </p> <p> It's possible that there's a bug in one of the other interfaces. The problem could also be dependent on some other feature of TT or on a specific compiler version. If you can provide a test case that fails, I'll look into it, otherwise, I'll close the issue. </p> <p> The compilers I used were VC 12 and gcc 4.8.3. </p> </description> <category>Ticket</category> </item> <item> <author>david@…</author> <pubDate>Fri, 03 Apr 2015 16:05:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:6</guid> <description> <p> Sorry for the previous post, you mentioned to test it... </p> <p> Ok, I retested too, with boost 1.57 (gcc, linux), it is ok for me. </p> </description> <category>Ticket</category> </item> <item> <author>david@…</author> <pubDate>Fri, 03 Apr 2015 16:35:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9201#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9201#comment:7</guid> <description> <p> Now I tested with BOOST_CONCEPT_ASSERT. I am not able to identify the code where it used to fail for me, so I can't exclude wrong usage (eh, I should have had put the usage into the issue text), but generally my code from that time is using BOOST_CONCEPT_ASSERT as well. Possibly I changed compiler since then (certainly: now I use native gcc 4.8.1, before I used windows crosscompiler, marked as experimental, let's blame that:) ). Anyway it seems ok now. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 03 Apr 2015 16:49:15 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9201#comment:8 https://svn.boost.org/trac10/ticket/9201#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> Ticket