This is the mail archive of the gcc-patches@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]

[C++ Patch] PR 61088


Hi,

again, a simple core issue, an ICE on invalid, with some rather more interesting side issues. The core is that we are not enforcing that an incomplete type cannot be captured by value. Thus the add_capture check. Then: 1- I'm also adding the early error_mark_node check because otherwise in some cases we ICE during error recovery when COMPLETE_TYPE_P gets an error_mark_node. I added the second function g() in the testcase to cover that. 2- I wish I could just do type = error_mark_node, for the by value capture error, like we do above for the VLA-related error, instead of returning error_mark_node, but that would result in a suboptimal diagnostic for the existing lambda-ice7.C. For it, we used to produce:

lambda-ice7.C: In function ‘void foo(A&)’:
lambda-ice7.C:8:3: error: invalid use of incomplete type ‘struct A’
[=](){a;};
^
lambda-ice7.C:4:8: error: forward declaration of ‘struct A’
struct A;
^
lambda-ice7.C:8:3: error: invalid use of incomplete type ‘struct A’
[=](){a;};
^
lambda-ice7.C:4:8: error: forward declaration of ‘struct A’
struct A;
^

and, after the patch:

lambda-ice7.C: In lambda function:
lambda-ice7.C:8:9: error: cannot capture by value ‘a’ of incomplete type ‘A’
[=](){a;};
^
lambda-ice7.C:4:8: note: forward declaration of ‘struct A’
struct A;
^

which I think is nearly optimal. With type = error_mark_node we would only add an additional error to the former.

3- The cxx_incomplete_type_inform check is because in some cases TYPE_MAIN_DECL can indeed be null (traditionally we used + which means location_of, which handles that). This happens for example for f() in the new testcase, and we don't emit any inform for it (at variance with lambda-ice7.C, for example). I think it's fine.

4- Finally, something I noticed while working on add_capture: right above the new check there is:

type = lambda_capture_field_type (initializer, explicit_init_p);
if (by_reference_p)
{
type = build_reference_type (type);
if (!real_lvalue_p (initializer))
error ("cannot capture %qE by reference", initializer);
}

now, interestingly, nothing in the testsuite exercises this error. And, so far, I failed to create a testcase for it. The Standard too doesn't seem to me so clear about that. Ideas?!?

Thanks!
Paolo.

/////////////////////////////

Attachment: CL_61088
Description: Text document

Attachment: patch_61088
Description: Text document


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