Skip to content

Wrong constraint for std::optional<T>::operator=(U&&) #37986

@jwakely

Description

@jwakely
mannequin
Bugzilla Link 38638
Resolution FIXED
Resolved on Jun 27, 2019 11:41
Version 6.0
OS All
CC @dwblaikie,@mclow

Extended Description

The following should compile:

#include
constexpr int foo(int i) {
std::optional o;
o = i;
return *o;
}

Wandbox tells me:

prog.cc:2:15: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
constexpr int foo(int i) {
^
prog.cc:4:5: note: non-constexpr function 'operator=<int &, void>' cannot be used in a constant expression
o = i;
^
/opt/wandbox/clang-6.0.0/include/c++/v1/optional:773:5: note: declared here
operator=(_Up&& __v)
^

https://wandbox.org/permlink/OrXOqTuQHDSddHod

The note shows that operator=(U&&) is being used, but that should not participate in overload resolution unless conjunction_v<is_scalar, is_same<T, decay_t>> is false.

In my code is_scalar is true, and is_same<int, decay_t<int&>> is true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillacompile-failUse [accepts-invalid] and [rejects-valid] insteadlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions