Modify

Ticket #12680 (closed Bugs: fixed)

Opened 5 months ago

Last modified 8 days ago

Inheriting constructors from Boost.Variant should be possible

Reported by: djh Owned by: apolukhin
Milestone: Boost 1.64.0 Component: variant
Version: Boost 1.62.0 Severity: Problem
Keywords: Cc:

Description

Suppose users want a strong typedef for their sumtypes. Instead of creating a weak type alias for a boost::variant the user should be able to inherit from the variant inheriting its constructors, too.

using TreeBase = boost::variant<Leaf, boost::recursive_wrapper<Node>>;

struct Tree : TreeBase {
  using TreeBase::TreeBase;

  // ...
};

Here is the full small self-contained example

https://gist.github.com/daniel-j-h/12c8b7f1c59b5a76c7e75dab38eb06fe#file-crash-cc

GCC crashing on this is ticketed upstream

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78767

Creating a new type for this use-case provides the user with type safety and should be the recommended way of using variant in any non-trivial code. Unfortunately, inheriting from Boost.Variant is not possible at the moment. The code example above does not compile.

In the Boost IRC channel Agustín Bergé told me this might be related to inheriting constructors with default arguments and that there are quirks related to SFINAE before C++17.

Attachments

crash.cc (473 bytes) - added by djh 5 months ago.

Change History

Changed 5 months ago by djh

comment:1 Changed 3 months ago by apolukhin

  • Owner changed from ebf to apolukhin
  • Status changed from new to assigned
  • Milestone changed from To Be Determined to Boost 1.64.0

Fixed by Mikhail Maximov in 217ee7f9. Fix will be marged to master, as soon as all the tests will cycle.

comment:2 Changed 8 days ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.