Boost C++ Libraries: Ticket #7120: ambiguous overload of convert_construct in variant when one of variant's value types derives from variant https://svn.boost.org/trac10/ticket/7120 <p> #include &lt;boost/variant.hpp&gt; </p> <p> struct X </p> <blockquote> <p> : boost::variant&lt; int &gt; </p> </blockquote> <p> { }; </p> <p> void main() { </p> <blockquote> <p> X x; boost::variant&lt;X&gt; y(x); </p> </blockquote> <p> } </p> <p> yields (MSVC9) </p> <p> 1&gt;------ Build started: Project: scratch, Configuration: Debug Win32 ------ 1&gt;Compiling... 1&gt;main.cpp 1&gt;c:\users\jeffrey\boost_1_49_0\boost\variant\variant.hpp(1405) : error C2666: 'boost::variant&lt;T0_&gt;::convert_construct' : 3 overloads have similar conversions 1&gt; with 1&gt; [ 1&gt; T0_=X 1&gt; ] 1&gt; c:\users\jeffrey\boost_1_49_0\boost\variant\variant.hpp(1384): could be 'void boost::variant&lt;T0_&gt;::convert_construct&lt;int,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_&gt;(const boost::variant&lt;int&gt; &amp;,long)' 1&gt; with 1&gt; [ 1&gt; T0_=X 1&gt; ] 1&gt; c:\users\jeffrey\boost_1_49_0\boost\variant\variant.hpp(1375): or 'void boost::variant&lt;T0_&gt;::convert_construct&lt;int,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_&gt;(boost::variant&lt;int&gt; &amp;,long)' 1&gt; with 1&gt; [ 1&gt; T0_=X 1&gt; ] 1&gt; c:\users\jeffrey\boost_1_49_0\boost\variant\variant.hpp(1315): or 'void boost::variant&lt;T0_&gt;::convert_construct&lt;T&gt;(T &amp;,int,boost::mpl::false_)' 1&gt; with 1&gt; [ 1&gt; T0_=X, 1&gt; T=X 1&gt; ] 1&gt; while trying to match the argument list '(X, long)' 1&gt; c:\users\jeffrey\scratch\main.cpp(10) : see reference to function template instantiation 'boost::variant&lt;T0_&gt;::variant&lt;X&gt;(T &amp;)' being compiled 1&gt; with 1&gt; [ 1&gt; T0_=X, 1&gt; T=X 1&gt; ] </p> <p> Basically, the problem appears to be the call to </p> <p> convert_construct(operand, 1L) <em> operand is of type X </em></p> <p> which cannot disambiguate between the overloads (simplified) </p> <p> void convert_construct([const] boost::variant&lt;T&gt;&amp; operand, long); void convert_construct(T&amp; operand, int); </p> <p> The former requires a derived-&gt;base conversion in the first argument, while the latter requires a long-&gt;int conversion in the second argument. Perhaps the dispatching among the convert_construct overloads should be more sophisticated? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7120 Trac 1.4.3 Antony Polukhin Mon, 30 May 2016 17:13:45 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/7120#comment:1 https://svn.boost.org/trac10/ticket/7120#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">ebf</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.62.0</span> </li> </ul> Ticket Antony Polukhin Mon, 30 May 2016 17:14:50 GMT <link>https://svn.boost.org/trac10/ticket/7120#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7120#comment:2</guid> <description> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/variant/commit/d23cdd3502b452231c6c6bc2f2d4298ca24b5650"><span class="icon">​</span>d23cdd35 develop</a>, will be merged to master branch as soon as the tests will cycle. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 04 Jul 2016 05:18:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7120#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7120#comment:3</guid> <description> <p> Any workaround for this? I have the exact same problem. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Igor R.</dc:creator> <pubDate>Sun, 21 Aug 2016 18:32:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7120#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7120#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7120#comment:2" title="Comment 2">apolukhin</a>: </p> <blockquote class="citation"> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/variant/commit/d23cdd3502b452231c6c6bc2f2d4298ca24b5650"><span class="icon">​</span>d23cdd35 develop</a>, will be merged to master branch as soon as the tests will cycle. </p> </blockquote> <p> Just for the record: the proposed fix fails the following code: </p> <pre class="wiki">#include &lt;boost/variant.hpp&gt; #include &lt;array&gt; template&lt;class Node&gt; struct node1_type; struct var_type; using var_base = boost::variant&lt;int, boost::recursive_wrapper&lt;node1_type&lt;var_type&gt;&gt; &gt;; template&lt;class Node&gt; struct node1_type { std::array&lt;Node, 1&gt; children; }; struct var_type : var_base { using var_base::var_base; }; int main() { var_type v1 = 1; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 20 Jan 2017 19:46:18 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/7120#comment:5 https://svn.boost.org/trac10/ticket/7120#comment:5 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.62.0</span> → <span class="trac-field-new">Boost 1.64.0</span> </li> </ul> <p> Fixed by Mikhail Maximov in <a class="ext-link" href="https://github.com/boostorg/variant/commit/217ee7f9ff769a1495e33f63d090ce70d54385a6"><span class="icon">​</span>217ee7f9</a>. Test case was added in <a class="ext-link" href="https://github.com/apolukhin/variant/commit/fbad41fb90e85cfcd3e60a665d662334cc1a2fb9"><span class="icon">​</span>fbad41fb</a>. As soon as the tests will cycle, will be merged to master branch. </p> Ticket Antony Polukhin Sat, 22 Apr 2017 05:59:47 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7120#comment:6 https://svn.boost.org/trac10/ticket/7120#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket