public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer
@ 2013-12-11 2:51 richard-gccbugzilla at metafoo dot co.uk
2014-01-09 16:18 ` [Bug c++/59465] " ostash at ostash dot kiev.ua
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2013-12-11 2:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Bug ID: 59465
Summary: g++ allows direct-initialization of an array of class
type from another array in a mem-initializer
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: richard-gccbugzilla at metafoo dot co.uk
Reduced testcase:
struct string {} a[1];
struct pair {
string s[1]; pair() : s(a) {}
};
This is ill-formed, but g++ accepts it. The initialization is rejected if we
try to direct-initialize a non-member array this way, or if 'string' is
replaced by a non-class type, so I assume this is a bug rather than a
deliberate extension.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
@ 2014-01-09 16:18 ` ostash at ostash dot kiev.ua
2021-08-04 19:37 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: ostash at ostash dot kiev.ua @ 2014-01-09 16:18 UTC (permalink / raw)
To: gcc-bugs
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) {};
^
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
2014-01-09 16:18 ` [Bug c++/59465] " ostash at ostash dot kiev.ua
@ 2021-08-04 19:37 ` pinskia at gcc dot gnu.org
2024-02-22 10:59 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 19:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-04
Keywords| |accepts-invalid
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
2014-01-09 16:18 ` [Bug c++/59465] " ostash at ostash dot kiev.ua
2021-08-04 19:37 ` pinskia at gcc dot gnu.org
@ 2024-02-22 10:59 ` pinskia at gcc dot gnu.org
2024-02-22 10:59 ` [Bug c++/59465] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-22 10:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jlame646 at gmail dot com
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114053 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (2 preceding siblings ...)
2024-02-22 10:59 ` pinskia at gcc dot gnu.org
@ 2024-02-22 10:59 ` pinskia at gcc dot gnu.org
2024-02-22 14:44 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-22 10:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|g++ allows |[11/12/13/14 Regression]
|direct-initialization of an |g++ allows
|array of class type from |direct-initialization of an
|another array in a |array of class type from
|mem-initializer |another array in a
| |mem-initializer
Known to work| |4.6.4
Target Milestone|--- |11.5
Known to fail| |4.7.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (3 preceding siblings ...)
2024-02-22 10:59 ` [Bug c++/59465] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-02-22 14:44 ` mpolacek at gcc dot gnu.org
2024-02-22 15:56 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-22 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
From bug 114053:
struct I {
const bool b;
};
struct O {
I a[2];
static I const data[2];
O() : a(data){}
} ;
I const O::data[2] = {true, false};
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (4 preceding siblings ...)
2024-02-22 14:44 ` mpolacek at gcc dot gnu.org
@ 2024-02-22 15:56 ` mpolacek at gcc dot gnu.org
2024-02-22 16:39 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-22 15:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We accept the test because we do
else if (type_build_ctor_call (type)
|| (init && CLASS_TYPE_P (strip_array_types (type))))
{
if (TREE_CODE (type) == ARRAY_TYPE)
{
if (init == NULL_TREE
|| same_type_ignoring_top_level_qualifiers_p (type,
TREE_TYPE (init)))
{
if (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
{
/* Initialize the array only if it's not a flexible
array member (i.e., if it has an upper bound). */
init = build_vec_init_expr (type, init, tf_warning_or_error);
init = cp_build_init_expr (decl, init);
finish_expr_stmt (init);
which results in something like
((struct O *) this)->a = <<< Unknown tree: vec_init_expr
D.2843
VIEW_CONVERT_EXPR<const struct I[2]>(data) >>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (5 preceding siblings ...)
2024-02-22 15:56 ` mpolacek at gcc dot gnu.org
@ 2024-02-22 16:39 ` mpolacek at gcc dot gnu.org
2024-02-23 0:22 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-22 16:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started to be accepted with r0-110915-ga034826198b771:
https://gcc.gnu.org/pipermail/gcc-patches/2011-August/320236.html
which was supposed to be a cleanup, not a deliberate change to start accepting
the code.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (6 preceding siblings ...)
2024-02-22 16:39 ` mpolacek at gcc dot gnu.org
@ 2024-02-23 0:22 ` mpolacek at gcc dot gnu.org
2024-03-22 14:43 ` cvs-commit at gcc dot gnu.org
2024-03-22 14:44 ` [Bug c++/59465] [11/12/13 " mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-23 0:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13/14 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (7 preceding siblings ...)
2024-02-23 0:22 ` mpolacek at gcc dot gnu.org
@ 2024-03-22 14:43 ` cvs-commit at gcc dot gnu.org
2024-03-22 14:44 ` [Bug c++/59465] [11/12/13 " mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-22 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:d1d8fd2884b44598d80de1038b086eec41519d4b
commit r14-9622-gd1d8fd2884b44598d80de1038b086eec41519d4b
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Feb 22 18:49:08 2024 -0500
c++: direct-init of an array of class type [PR59465]
...from another array in a mem-initializer should not be accepted.
We already reject
struct string {} a[1];
string x[1](a);
but
struct pair {
string s[1];
pair() : s(a) {}
};
is wrongly accepted.
It started to be accepted with r0-110915-ga034826198b771:
<https://gcc.gnu.org/pipermail/gcc-patches/2011-August/320236.html>
which was supposed to be a cleanup, not a deliberate change to start
accepting the code. The build_vec_init_expr code was added in r165976:
<https://gcc.gnu.org/pipermail/gcc-patches/2010-October/297582.html>.
It appears that we do the magic copy array when we have a defaulted
constructor and we generate code for its mem-initializer which
initializes an array. I also see that we go that path for compound
literals. So when initializing an array member, we can limit building
up a VEC_INIT_EXPR to those special cases.
PR c++/59465
gcc/cp/ChangeLog:
* init.cc (can_init_array_with_p): New.
(perform_member_init): Check it.
gcc/testsuite/ChangeLog:
* g++.dg/init/array62.C: New test.
* g++.dg/init/array63.C: New test.
* g++.dg/init/array64.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/59465] [11/12/13 Regression] g++ allows direct-initialization of an array of class type from another array in a mem-initializer
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
` (8 preceding siblings ...)
2024-03-22 14:43 ` cvs-commit at gcc dot gnu.org
@ 2024-03-22 14:44 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-03-22 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59465
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12/13/14 Regression] |[11/12/13 Regression] g++
|g++ allows |allows
|direct-initialization of an |direct-initialization of an
|array of class type from |array of class type from
|another array in a |another array in a
|mem-initializer |mem-initializer
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 14. I don't think I'll backport it.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-03-22 14:44 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-11 2:51 [Bug c++/59465] New: g++ allows direct-initialization of an array of class type from another array in a mem-initializer richard-gccbugzilla at metafoo dot co.uk
2014-01-09 16:18 ` [Bug c++/59465] " ostash at ostash dot kiev.ua
2021-08-04 19:37 ` pinskia at gcc dot gnu.org
2024-02-22 10:59 ` pinskia at gcc dot gnu.org
2024-02-22 10:59 ` [Bug c++/59465] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-22 14:44 ` mpolacek at gcc dot gnu.org
2024-02-22 15:56 ` mpolacek at gcc dot gnu.org
2024-02-22 16:39 ` mpolacek at gcc dot gnu.org
2024-02-23 0:22 ` mpolacek at gcc dot gnu.org
2024-03-22 14:43 ` cvs-commit at gcc dot gnu.org
2024-03-22 14:44 ` [Bug c++/59465] [11/12/13 " mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).