[Bug c++/59465] g++ allows direct-initialization of an array of class type from another array in a mem-initializer

ostash at ostash dot kiev.ua gcc-bugzilla@gcc.gnu.org
Thu Jan 9 16:18:00 GMT 2014


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

Viktor Ostashevskyi <ostash at ostash dot kiev.ua> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ostash at ostash dot kiev.ua

--- Comment #1 from Viktor Ostashevskyi <ostash at ostash dot kiev.ua> ---
Another test case:

static const int my_size = 10;

class UserType
{
public:
  UserType(): f_(){}
private:
int f_;
};

#if 1
typedef UserType Array[my_size];
#else
typedef char Array[my_size];
#endif

class Foo
{
public:
  Foo(Array& m) : m_(m) {};
private:
  Array m_;
};

Target: x86_64-pc-linux-gnu
gcc version 4.8.3 20140102 (prerelease)

In case when Array is char, g++ correctly states:
error: array used as initializer
   Foo(Array& m) : m_(m) {};
                       ^
but when Array is UserType there is no error.

clang 3.4 correctly produces an error for both cases:
error: array initializer must be an initializer list or string literal
  Foo(Array& m) : m_(m) {};
                  ^

or

error: array initializer must be an initializer list
  Foo(Array& m) : m_(m) {};
                  ^



More information about the Gcc-bugs mailing list