[Bug c++/37898] New: aggregates vs. defaulted deleted functions

bkoz at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Oct 22 22:59:00 GMT 2008


Aggregate defined in 8.5.1 as:

  An aggregate is an array or a class (Clause 9) with no user-provided
constructors (12.1), no private or protected non-static data members (Clause
11), no base classes (Clause 10), and no virtual functions (10.3).

Perhaps this is an aggregate:

struct aggregate
{
  int i;

  aggregate() = default;
  ~aggregate() = default;
  aggregate& operator=(const aggregate&) = delete;
  aggregate(const aggregate&) = delete;
};

>From 8.4, p 9
  A special member function is user-provided if it is user-declared
and not explicitly defaulted on its first declaration.

Conclude:
  // -> as explicitly defaulted on first decl, no user-provided ctors
  // -> this is an aggregate

Thus, this should work:


struct aggregate
{
  int i;

  // 8.4 p 9, 
  // A special member function is user-provided if it is user-declared
  // and not explicitly defaulted on its first declaration.
  // -> as explicitly defaulted on first decl, this is not user-provided. 
  // -> this is an aggregate
#if 1
  aggregate() = default;
  ~aggregate() = default;
  aggregate& operator=(const aggregate&) = delete;
  aggregate(const aggregate&) = delete;
#endif
};


int main()
{
  typedef aggregate test_type;

  // copy list initialization
  test_type t1 = { 1 };

  // copy list initialization smaller than size of array, array 
  test_type t2[4] = { 1, 2, 3 };
}

Instead, get:

%$bld/H-x86-gcc.20081020/bin/g++ -std=c++0x -c atomic_init_forms-5.cc
atomic_init_forms-5.cc: In function 'int main()':
atomic_init_forms-5.cc:25: error: no matching function for call to
'aggregate::aggregate(<brace-enclosed initializer list>)'
atomic_init_forms-5.cc:15: note: candidates are: aggregate::aggregate(const
aggregate&)
atomic_init_forms-5.cc:28: error: conversion from 'int' to non-scalar type
'main()::test_type' requested
atomic_init_forms-5.cc:28: error: conversion from 'int' to non-scalar type
'main()::test_type' requested
atomic_init_forms-5.cc:28: error: conversion from 'int' to non-scalar type
'main()::test_type' requested


-- 
           Summary: aggregates vs. defaulted deleted functions
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bkoz at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37898



More information about the Gcc-bugs mailing list