Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jwakely mannequin opened this issue Aug 20, 2018 · 2 comments
Closed

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

jwakely mannequin opened this issue Aug 20, 2018 · 2 comments
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@jwakely
Copy link
Mannequin

jwakely mannequin commented Aug 20, 2018

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.

@jwakely
Copy link
Mannequin Author

jwakely mannequin commented Aug 20, 2018

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

Actually, in all code is_scalar is true, I'm not special ;-)

@mclow
Copy link
Contributor

mclow commented Jun 27, 2019

Fixed in revision 364574.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

1 participant