[llvm-bugs] [Bug 25692] New: User-declared destructor makes all the defaulted assignment operators non-constexpr defined

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 1 04:20:56 PST 2015


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

            Bug ID: 25692
           Summary: User-declared destructor makes all the defaulted
                    assignment operators non-constexpr defined
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tomilovanatoliy at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

In following code all defaulted assignment operators recognized as
non-constexpr:

struct S
{
    S() = default;
    S(S const &) = default;
    S(S &&) = default;
    S & operator = (S const &) = default;
    S & operator = (S &&) = default;
    ~S() = default;
};

inline constexpr bool test()
{
    S a;
    S b;
    a = b; // !
    //a = std::move(b); // equally the same error
    return true;
}

static_assert(test());

Code fails to compile at line marked by // !
An error message is:

/home/user/cpp/main.cpp:21:23: error: constexpr function never produces a
constant expression [-Winvalid-constexpr]
inline constexpr bool test()
                      ^
/home/user/cpp/main.cpp:25:7: note: non-constexpr function 'operator=' cannot
be used in a constant expression
    a = b;
      ^
/home/user/cpp/main.cpp:16:9: note: declared here
    S & operator = (S &) = default;
        ^
/home/user/cpp/main.cpp:29:15: error: static_assert expression is not an
integral constant expression
static_assert(test());
              ^~~~~~
/home/user/cpp/main.cpp:25:7: note: non-constexpr function 'operator=' cannot
be used in a constant expression
    a = b;
      ^
/home/user/cpp/main.cpp:29:15: note: in call to 'test()'
static_assert(test());
              ^
/home/user/cpp/main.cpp:16:9: note: declared here
    S & operator = (S &) = default;
        ^
2 errors generated.

Commenting out destructor makes code to compile fine.

-- 
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/20151201/e9f8c574/attachment.html>


More information about the llvm-bugs mailing list