diff mbox

[C++] PR 52487

Message ID 4F68E9F2.7070406@oracle.com
State New
Headers show

Commit Message

Paolo Carlini March 20, 2012, 8:34 p.m. UTC
... this simple also passes testing.

Paolo.

////////////////////
/cp
2012-03-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/52487
	* class.c (check_field_decls): Call literal_type_p only
	on complete types.

/testsuite
2012-03-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/52487
	* g++.dg/cpp0x/lambda/lambda-ice7.C: New.

Comments

Jason Merrill March 22, 2012, 2:49 p.m. UTC | #1
It's ill-formed to have a field with incomplete type.  The best thing 
would be to complain about that before we get to literal_type_p so that 
errorcount is set, if that's not too complicated.

Jason
Paolo Carlini March 22, 2012, 4:58 p.m. UTC | #2
On 03/22/2012 03:49 PM, Jason Merrill wrote:
> It's ill-formed to have a field with incomplete type.  The best thing 
> would be to complain about that before we get to literal_type_p so 
> that errorcount is set, if that's not too complicated.
Agreed. The problem is that if we just change check_field_decls to 
produce an error about the incomplete field, we produce also another 
later: that is, considering cp_parser_lambda_expression, we get to 
check_field_decls from finish_struct, but we eventually also produce an 
error with cxx_incomplete_type_diagnostic from build_lambda_object (-> 
force_rvalue -> build_special_member_call -> 
complete_type_or_maybe_complain)

Anyway, I also think not calling literal_type_p from check_field_decls 
if the type is incomplete is pretty ugly, but I'm not sure which is the 
best way to make progress: I could try returning a boolean from 
check_field_decls if something goes wrong in order to bail out early 
from cp_parser_lambda_expression (at the moment, finish_struct_1, 
check_bases_and_members, all return void). Or I could try to catch the 
incomplete field even *before* check_field_decls.

What do you suggest?

Thanks,
Paolo.
Gabriel Dos Reis March 22, 2012, 5:15 p.m. UTC | #3
On Thu, Mar 22, 2012 at 11:58 AM, Paolo Carlini
<paolo.carlini@oracle.com> wrote:
> On 03/22/2012 03:49 PM, Jason Merrill wrote:
>>
>> It's ill-formed to have a field with incomplete type.  The best thing
>> would be to complain about that before we get to literal_type_p so that
>> errorcount is set, if that's not too complicated.
>
> Agreed. The problem is that if we just change check_field_decls to produce
> an error about the incomplete field, we produce also another later: that is,

Can't we set a bit saying that the field has already gone through
diagnostics, just
like we do when trying to avoid duplicate warnings?

> considering cp_parser_lambda_expression, we get to check_field_decls from
> finish_struct, but we eventually also produce an error with
> cxx_incomplete_type_diagnostic from build_lambda_object (-> force_rvalue ->
> build_special_member_call -> complete_type_or_maybe_complain)
>
> Anyway, I also think not calling literal_type_p from check_field_decls if
> the type is incomplete is pretty ugly, but I'm not sure which is the best
> way to make progress: I could try returning a boolean from check_field_decls
> if something goes wrong in order to bail out early from
> cp_parser_lambda_expression (at the moment, finish_struct_1,
> check_bases_and_members, all return void). Or I could try to catch the
> incomplete field even *before* check_field_decls.
>
> What do you suggest?
>
> Thanks,
> Paolo.
>
Jason Merrill March 22, 2012, 6:28 p.m. UTC | #4
On 03/22/2012 12:58 PM, Paolo Carlini wrote:
> Anyway, I also think not calling literal_type_p from check_field_decls
> if the type is incomplete is pretty ugly, but I'm not sure which is the
> best way to make progress

I guess that's OK.  Just add a comment explaining that we'll get an 
error later.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C	(revision 0)
@@ -0,0 +1,9 @@ 
+// PR c++/52487
+// { dg-options "-std=c++0x" }
+
+struct A;         // { dg-error "forward declaration" }
+
+void foo(A& a)
+{
+  [=](){a;};      // { dg-error "invalid use of incomplete type" }
+}
Index: cp/class.c
===================================================================
--- cp/class.c	(revision 185588)
+++ cp/class.c	(working copy)
@@ -3150,7 +3150,7 @@  check_field_decls (tree t, tree *access_decls,
 
       /* If at least one non-static data member is non-literal, the whole
          class becomes non-literal.  */
-      if (!literal_type_p (type))
+      if (COMPLETE_TYPE_P (type) && !literal_type_p (type))
         CLASSTYPE_LITERAL_P (t) = false;
 
       /* A standard-layout class is a class that: