This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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) {};
                  ^


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]