Skip to content

defaulted destructor makes defaulted copy constructor non-constexpr #37491

Closed
@mclow

Description

@mclow
Bugzilla Link 38143
Version trunk
OS All
CC @DougGregor,@marehr,@zygoloid

Extended Description

Consider this code:

class span {
public:
    using pointer                = const int *;

    constexpr span() : __data{nullptr} {}

    constexpr span           (const span&) noexcept = default;
    constexpr span& operator=(const span&) noexcept = default;
    ~span() noexcept = default;

    constexpr pointer data()    const noexcept { return __data; }

private:
    pointer __data;
};

When compiled with a recent clang [clang version 7.0.0 (trunk 336548)], (-std=c++2a) it gives an error:

junk.cpp:8:5: error: defaulted definition of copy assignment operator is not
      constexpr
    constexpr span& operator=(const span&) noexcept = default;
    ^

However, if I switch the order of the two lines to:
    ~span() noexcept = default;
    constexpr span& operator=(const span&) noexcept = default;

then it compiles w/o error.

However, I believe that it should compile w/o error in both cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions