optional is "is_copy_constructible" when T is not.

Open
#54 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

Start with the Godbolt reproducer and the boost/optional.hpp header, then trace how boost::optional determines its copy-constructibility. Compare that result with std::optional for a type whose copy constructor is deleted but move operations are available. Done means the final static assertion passes, with regression coverage added if the repository provides a relevant test location.

Written by the indexing model from the issue text.

Description

Hi.
I encountered issues while trying to use std::vector<boost::optional<std::tuple<NonCopyable, std::function<...>>>. THis failed to compile on msvc.

Looks like it boiled down to this repro: https://godbolt.org/g/cFNcUN

#include <boost/optional.hpp>
#include <type_traits>
#include <optional>

struct NonCopyAble
{
    NonCopyAble() = default;

    NonCopyAble(const NonCopyAble&) = delete;
    NonCopyAble& operator=(const NonCopyAble&) = delete;

    NonCopyAble(NonCopyAble&&) = default;
    NonCopyAble& operator=(NonCopyAble&&) = default;
};

static_assert(!std::is_copy_constructible<NonCopyAble>::value, "NonCopyAble is_copy_constructible when shouldn't be");
static_assert(!std::is_copy_constructible<std::optional<NonCopyAble>>::value, "std::optional<NonCopyAble> is_copy_constructible when shouldn't be");    
static_assert(!std::is_copy_constructible<boost::optional<NonCopyAble>>::value, "boost::optional<NonCopyAble> is_copy_constructible when shouldn't be");    // This assert fails
Dominant language
C++
Stars
60
Forks
75
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from boostorg/optional

All issues in boostorg/optional

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.