Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Jason Merrill
OK, thanks. On Wed, Dec 14, 2016 at 12:01 PM, Marek Polacek wrote: > On Wed, Dec 14, 2016 at 11:30:17AM -0500, Jason Merrill wrote: >> On Wed, Dec 14, 2016 at 10:39 AM, Marek Polacek wrote: >> > + if (TREE_CODE (type) == ARRAY_TYPE >> > + &&

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Marek Polacek
On Wed, Dec 14, 2016 at 11:30:17AM -0500, Jason Merrill wrote: > On Wed, Dec 14, 2016 at 10:39 AM, Marek Polacek wrote: > > + if (TREE_CODE (type) == ARRAY_TYPE > > + && TYPE_DOMAIN (type) == NULL_TREE > > + && init != NULL_TREE) > > + error_at

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Jason Merrill
On Wed, Dec 14, 2016 at 10:39 AM, Marek Polacek wrote: > + if (TREE_CODE (type) == ARRAY_TYPE > + && TYPE_DOMAIN (type) == NULL_TREE > + && init != NULL_TREE) > + error_at (DECL_SOURCE_LOCATION (current_function_decl), > + "member

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Marek Polacek
On Wed, Dec 14, 2016 at 09:04:01AM -0500, Jason Merrill wrote: > On Wed, Dec 14, 2016 at 8:16 AM, Marek Polacek wrote: > > + if (TREE_CODE (type) == ARRAY_TYPE > > + && TYPE_DOMAIN (type) == NULL_TREE > > + && init != NULL_TREE) > > + error_at

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Jason Merrill
On Wed, Dec 14, 2016 at 8:16 AM, Marek Polacek wrote: > + if (TREE_CODE (type) == ARRAY_TYPE > + && TYPE_DOMAIN (type) == NULL_TREE > + && init != NULL_TREE) > + error_at (DECL_SOURCE_LOCATION (member), > + "initialization of a

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-14 Thread Marek Polacek
On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: > On 12/08/2016 01:05 PM, Jason Merrill wrote: > > If the problem is the member initializer, we can diagnose that > > directly rather than wait until we're in a constructor. > > What about: > struct Foo { > int a; > char ary[]; > Foo

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-13 Thread Martin Sebor
On 12/13/2016 02:32 PM, Jason Merrill wrote: On 12/13/2016 03:25 PM, Martin Sebor wrote: On 12/13/2016 12:06 PM, Jason Merrill wrote: On 12/09/2016 07:46 PM, Martin Sebor wrote: On 12/09/2016 02:49 PM, Jason Merrill wrote: On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-13 Thread Jason Merrill
On 12/13/2016 03:25 PM, Martin Sebor wrote: On 12/13/2016 12:06 PM, Jason Merrill wrote: On 12/09/2016 07:46 PM, Martin Sebor wrote: On 12/09/2016 02:49 PM, Jason Merrill wrote: On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor wrote: For flexible array members, because

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-13 Thread Martin Sebor
On 12/13/2016 12:06 PM, Jason Merrill wrote: On 12/09/2016 07:46 PM, Martin Sebor wrote: On 12/09/2016 02:49 PM, Jason Merrill wrote: On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor wrote: For flexible array members, because they're not in C++, we get to make up the rules

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-13 Thread Jason Merrill
On 12/09/2016 07:46 PM, Martin Sebor wrote: On 12/09/2016 02:49 PM, Jason Merrill wrote: On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor wrote: For flexible array members, because they're not in C++, we get to make up the rules that make the most sense to us. IMO, they should

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Martin Sebor
On 12/09/2016 02:49 PM, Jason Merrill wrote: On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor wrote: For flexible array members, because they're not in C++, we get to make up the rules that make the most sense to us. IMO, they should fit in well with the rest of the language.

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Jason Merrill
On Fri, Dec 9, 2016 at 11:33 AM, Martin Sebor wrote: > For flexible array members, because they're not in C++, we get to > make up the rules that make the most sense to us. IMO, they should > fit in well with the rest of the language. I disagree; we should support C code, but

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Martin Sebor
On 12/09/2016 08:34 AM, Nathan Sidwell wrote: On 12/09/2016 10:18 AM, Martin Sebor wrote: On 12/09/2016 08:09 AM, Jakub Jelinek wrote: On Fri, Dec 09, 2016 at 08:04:11AM -0700, Martin Sebor wrote: then (IMO) so is this: struct Foo { int a; char ary[]; Foo () : ary ("bob") {}

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Nathan Sidwell
On 12/09/2016 10:18 AM, Martin Sebor wrote: On 12/09/2016 08:09 AM, Jakub Jelinek wrote: On Fri, Dec 09, 2016 at 08:04:11AM -0700, Martin Sebor wrote: then (IMO) so is this: struct Foo { int a; char ary[]; Foo () : ary ("bob") {} }; So what does this mean? Assume that the

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Martin Sebor
On 12/09/2016 08:09 AM, Jakub Jelinek wrote: On Fri, Dec 09, 2016 at 08:04:11AM -0700, Martin Sebor wrote: I'm not sure I understand what you mean. Since the following is valid and meaningful (i.e., initializes the array with the elements of the string): struct Foo { int a; char

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Jakub Jelinek
On Fri, Dec 09, 2016 at 08:04:11AM -0700, Martin Sebor wrote: > I'm not sure I understand what you mean. Since the following is > valid and meaningful (i.e., initializes the array with the elements > of the string): > > struct Foo { >int a; >char ary[4]; >Foo () : ary ("bob") {} >

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Martin Sebor
On 12/09/2016 05:34 AM, Nathan Sidwell wrote: On 12/08/2016 03:42 PM, Martin Sebor wrote: On 12/08/2016 01:28 PM, Marek Polacek wrote: On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: struct Foo { int a; char ary[]; Foo () : ary ("bob"){} Clang accepts this test case

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Nathan Sidwell
On 12/08/2016 03:42 PM, Martin Sebor wrote: On 12/08/2016 01:28 PM, Marek Polacek wrote: On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: struct Foo { int a; char ary[]; Foo () : ary ("bob"){} Clang accepts this test case although it does reject the originally submitted

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-09 Thread Marek Polacek
On Thu, Dec 08, 2016 at 01:42:44PM -0700, Martin Sebor wrote: > On 12/08/2016 01:28 PM, Marek Polacek wrote: > > On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: > > > On 12/08/2016 01:05 PM, Jason Merrill wrote: > > > > If the problem is the member initializer, we can diagnose that

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-08 Thread Martin Sebor
On 12/08/2016 01:28 PM, Marek Polacek wrote: On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: On 12/08/2016 01:05 PM, Jason Merrill wrote: If the problem is the member initializer, we can diagnose that directly rather than wait until we're in a constructor. What about: struct

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-08 Thread Marek Polacek
On Thu, Dec 08, 2016 at 02:56:56PM -0500, Nathan Sidwell wrote: > On 12/08/2016 01:05 PM, Jason Merrill wrote: > > If the problem is the member initializer, we can diagnose that > > directly rather than wait until we're in a constructor. > > What about: > struct Foo { > int a; > char ary[]; > Foo

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-08 Thread Nathan Sidwell
On 12/08/2016 01:05 PM, Jason Merrill wrote: If the problem is the member initializer, we can diagnose that directly rather than wait until we're in a constructor. What about: struct Foo { int a; char ary[]; Foo () : ary ("bob"){} }; ? That ICEs in the same way. nathan -- Nathan Sidwell

Re: C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-08 Thread Jason Merrill
If the problem is the member initializer, we can diagnose that directly rather than wait until we're in a constructor. On Wed, Dec 7, 2016 at 3:26 PM, Marek Polacek wrote: > We were crashing in finish_expr_stmt here: > 676 /* If we ran into a problem, make sure we

C++ PATCH to reject initializating flexible array members in constructors (PR c++/72775)

2016-12-07 Thread Marek Polacek
We were crashing in finish_expr_stmt here: 676 /* If we ran into a problem, make sure we complained. */ 677 gcc_assert (expr != error_mark_node || seen_error ()); Well, we ran into a problem, but never raised an error. The problem was that we couldn't determine the max index of the