https://bugs.llvm.org/show_bug.cgi?id=38638

            Bug ID: 38638
           Summary: Wrong constraint for std::optional<T>::operator=(U&&)
           Product: libc++
           Version: 6.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: zi...@kayari.org
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com

The following should compile:

#include <optional>
constexpr int foo(int i) {
  std::optional<int> 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<T>,
is_same<T, decay_t<U>>> is false.

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to