[llvm-bugs] [Bug 38983] New: Spurious interaction between noexcept specs. for move/copy assignment

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 18 05:57:18 PDT 2018


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

            Bug ID: 38983
           Summary: Spurious interaction between noexcept specs. for
                    move/copy assignment
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: oliver.rosten at googlemail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following (contrived) code appears to indicate a spurious dependency
between the exception specifications for the move/copy assignment operators.

template<class T>
class wrapper
{
  T& m_Ref; 
// Reported problem disappears if reference_wrapper is used instead
public:
  wrapper(T& ref) : m_Ref{ref} {}

  wrapper(const wrapper&)            = default;
  wrapper(wrapper&&)                 noexcept = default;
  wrapper& operator=(const wrapper&) noexcept(false){} 
  // 'false' required to reveal bug; 
  //removing false fixes compilation
  wrapper& operator=(wrapper&&)      noexcept = default;

};

template<class T, class W>
class thing
{
private:
  W m_Member{};
public:
  thing(T& ref) : m_Member{ref} {}

  thing(const thing&) = default;
  thing(thing&&)      = default;

  thing& operator=(const thing&)     = default;
  thing& operator=(thing&&) noexcept = default;
};

int x{5};
wrapper<int> w{x}; // fine
thing<int, wrapper<int>> foo{x}; 

Compiler error message:
  exception specification of
  explicitly defaulted move assignment operator does not match the
  calculated one
    thing& operator=(thing&&) noexcept = default;

The last line of code fails to compile due to the exception spec of the *move*
assignment operator not matching the calculated one.

Compilation may be fixed by changing the exception spec. of the *copy*
assignment operator.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180918/095652d5/attachment.html>


More information about the llvm-bugs mailing list