<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Wrong default move constructor for union"
   href="http://llvm.org/bugs/show_bug.cgi?id=15432">15432</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong default move constructor for union
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.2
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>duvan.llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the code below, the default move constructor for Bug seems to not move the
union. If the line for the copy constructor, defined as "default", for the
class Data is removed (which should be a no-op?), then things seem to work.

(I'm using clang 3.2 on Snow Leopard.)

Reduced testcase:

#include <iostream>
#include <cstdint>

enum Type : uint32_t { Zero  = 0, One = 1, Two = 2, Mask = 3, Rest = 0xfffffffc
};

struct Data {
    explicit constexpr Data(uint32_t data = 0, Type type = Zero) : dataM(data
<< 2 | type) {}
    constexpr Data(Data const& data, Type type) : dataM(data.dataM | type) {}
    Data(Data const&) = default;

    Type type() const { return Type(dataM & Mask); }
    Data remove_type() const { Data copy(*this); copy.dataM &= Rest; return
copy; }
    uint32_t dataM;
};

inline std::ostream& operator<<(std::ostream& stream, Data id) { return stream
<< id.dataM; }

class Bug
{
public:
    Bug(Data id1, Data id2) : data(id1), first(id2, Two) {}
    Bug(Bug&&) = default;

    Type type() const { return first.type(); }
    Data no_1() const { return first.remove_type(); }

    friend std::ostream& operator<<(std::ostream& stream, Bug const& bug)
    {
        switch (bug.type())
        {
        case Zero:
            return stream << "0: " << bug.data.index << " (" << bug.first <<
')' << std::endl ;
        case One:
            return stream << "1: " << bug.no_1();
        case Two:
            return stream << "2: " << bug.no_1() << ' ' << bug.data.second;
        default:
            return stream;
        }
    }
private: 
    union U {
        U() {}
        explicit U(unsigned index) : index(index) {}
        explicit U(Data id) : second(id) {}
        unsigned index;
        Data second;
    }; 

    U data;
    Data first;
};

int main() {
    Bug a(Data(1), Data(2));
    std::cout << a << std::endl;
    Bug b(std::move(a));
    std::cout << b << std::endl;
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>