[llvm-bugs] [Bug 40555] New: clang emits misleading diagnostic messages about copy assignment operators when a class has a nested anonymous union member

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 31 14:24:16 PST 2019


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

            Bug ID: 40555
           Summary: clang emits misleading diagnostic messages about copy
                    assignment operators when a class has a nested
                    anonymous union member
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ahatanak at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

When the following code is compiled, the diagnostic message says the copy
assignment operator of the containing class is deleted because the variant
field has a non-trivial copy assignment operator instead of saying it has a
deleted copy assignment operator.

$ cat test.cpp
struct S0 {
  S0(const S0 &);
  S0 &operator=(const S0 &);
  int *p;
};

struct S1 {
  union {
    union { // copy assignment operator is deleted because of s10.
      S0 s10;
      int b;
    };
    int c;
  };
  ~S1();
};

S1 *x0;

void testC1(S1 *a0) {
  *a0 = *x0;
  *a0 = static_cast<S1&&>(*x0);
}

$ clang++ -std=c++11 -c test.cpp
test.cpp:21:7: error: object of type 'S1' cannot be assigned because its copy
      assignment operator is implicitly deleted
  *a0 = *x0; // error: object of type 'S1' cannot be assigned because it...
      ^
test.cpp:9:5: note: copy assignment operator of 'S1' is implicitly deleted
      because variant field '' has a non-trivial copy assignment operator
    union { // copy assignment operator of 'S1' is implicitly deleted bec...
    ^
test.cpp:22:7: error: object of type 'S1' cannot be assigned because its copy
      assignment operator is implicitly deleted
  *a0 = static_cast<S1&&>(*x0); // error: object of type 'S1' cannot be a...
      ^
test.cpp:9:5: note: copy assignment operator of 'S1' is implicitly deleted
      because variant field '' has a non-trivial copy assignment operator
    union { // copy assignment operator of 'S1' is implicitly deleted bec...
    ^
2 errors generated.

-- 
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/20190131/d2cd6270/attachment.html>


More information about the llvm-bugs mailing list