[llvm-bugs] [Bug 41991] New: c++2a: unable to set attributes to defaulted member functions

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 23 02:04:20 PDT 2019


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

            Bug ID: 41991
           Summary: c++2a: unable to set attributes to defaulted member
                    functions
           Product: clang
           Version: 8.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: development at jordi.vilar.cat
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

The following code, compiled with clang-8 -std=c++2a, fails with:
  error: an attribute list cannot appear here

(it also issues error: only special member functions may be defaulted, but this
is reported in a separated bug report #41989)

#include <compare>

struct type
{
// original
    [[nodiscard]] friend constexpr std::strong_equality operator<=>(const
type&, const type&) noexcept = default;

//  variant #1
//    [[nodiscard]] friend constexpr std::strong_equality operator<=>(const
type&, const type&) noexcept;

// variant #2
//    [[nodiscard]] friend constexpr std::strong_equality operator<=>(const
type&, const type&) noexcept { return std::strong_ordering::equal; }
};

With variant #1, clang complaints with the same error, this time is correct as
attribues for friend declarations are not allowed as per specs.

With variant #2, clang accepts the code with no complaints as the friend
operator is now a definition and attributes are allowed in this case.

With the original variant, clang applies the rule for friend declaration when
in fact it is a (implicit) definition, that is, the friend operator is not
expected to be later defined.

-- 
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/20190523/0c9ed138/attachment-0001.html>


More information about the llvm-bugs mailing list