mapbox / mapbox/variant

std::is_copy_constructible::value is always true for variant<Ts...>

Open
#151 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Description

The copy constructor only actually compiles when all member types are copyable, as it should. However, when checking whether the variant type is copy-constructible via SFINAE, e.g. with `std::is_copy_constructible`, you will always get `true`, because the copy constructor always exists, whether or not it is valid. The same applies to move constructors, and copy / move assignment operators.

I first thought I could fix this with a simple `enable_if` on each of the methods, but as it turns out I can't because if you make templates out of any of these special methods, they are not those special methods anymore. I did find a [solution] on StackOverflow, though I'm not entirely certain if it might introduce unwanted side effects. Could you have a look? In case it seems unproblematic to you, I would be happy to try implementing it here.

[solution]: https://stackoverflow.com/a/27073263/1592377

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the variant implementation's special member constructors and the linked Stack Overflow solution; the issue names no source file or test. Determine whether copy and move type traits correctly reflect non-copyable alternatives without unwanted side effects, then verify the resulting behavior with focused coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.