https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107340

            Bug ID: 107340
           Summary: std::unordered_map and completeness of nested classes
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jens.maurer at gmx dot net
  Target Milestone: ---

Consider:

#include <unordered_map>

struct X
{
  struct Key
  {
    int x = 0;

    bool operator==(const Key&) const = default;

    std::size_t operator()(const Key& k) const noexcept
    {
      return k.x;
    }
  };

  int a[sizeof(Key)];

  std::unordered_map<Key, std::size_t, Key> m;
};

X x;

When compiled with "g++ -std=c++20", it yields:

a1.cc:24:3: error: use of deleted function ‘X::X()’
(plus lots of details)

since gcc 11.3 and 12.x; gcc 11.2 compiled this code fine.

Analysis: The nested class "X::Key" is complete at its closing brace, also
evidenced by the array data member declaration.  Yet, "m" attains a deleted
default constructor for no apparent reason.

Moving class "Key" to namespace scope or providing a separate, but still
nested, "X::KeyHash" class works around the issue.

Reply via email to