<html>
    <head>
      <base href="https://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 --- - Improper alignment in pointer cast in unordered_map of std::aligned_storage"
   href="https://llvm.org/bugs/show_bug.cgi?id=31849">31849</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Improper alignment in pointer cast in unordered_map of std::aligned_storage
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david@doublewise.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This might be related to <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED WONTFIX - operator new and STL containers silently ignore element alignment"
   href="show_bug.cgi?id=22634">https://llvm.org/bugs/show_bug.cgi?id=22634</a>

#include <unordered_map>

struct S {
    void emplace() {
        m_map.emplace(
            std::piecewise_construct,
            std::forward_as_tuple(0),
            std::forward_as_tuple()
        );
    }
private:
    std::int64_t x;
    // std::int64_t y;
    using mapped_type = typename std::aligned_storage<3*sizeof(void*)>::type;
    std::unordered_map<int, mapped_type> m_map;
};

int main() {
    S s;
    s.emplace();
}




clang++ -stdlib=libc++ -fsanitize=address -fsanitize=undefined -std=c++1z
main.cpp && ./a.out


include/c++/v1/__hash_table:2152:29: runtime error: downcast of misaligned
address 0x7ff2d6c62f8 for type
'std::__1::__hash_node<std::__1::__hash_value_type<int,
std::__1::aligned_storage<24, 16>::type, void *>', which requires 16 byte
alignment



However, unlike with <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED WONTFIX - operator new and STL containers silently ignore element alignment"
   href="show_bug.cgi?id=22634">bug 22634</a> this can result from no particular use of
alignment specifiers in user code. This exact sanitizer error can also be
triggered by using std::function<anything(anything...)> as the mapped_type, as
it contains std::aligned_storage in it.</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>