This causes the compiler to crash when trying to compute a layout for
the lambda closure type (see included test).
Details
Diff Detail
Event Timeline
Thanks!
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
14972 | You'll need to use FieldType->getBaseElementTypeUnsafe() or similar here to handle the case where the field type is an array whose element type is a class. (That can happen in a lambda if you capture a local array variable by value.) | |
14974 | For consistency with the class case, I think we should mark the field invalid in this case too. |
Fixed some issues pointed out in review comments:
- call to getBaseElementType before checking type validity.
- when the type is incomplete, mark not only the lambda closure type as invalid but also the field
Also, added a couple of checks to resemble more closely the code that checks user-declared fields in classes.
Thanks! Some simplifications are possible here, but otherwise this looks good.
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
14972 | Hah, OK, now you've switched to using RequireCompleteType this has become redundant again (it'll walk to the base element type for you). =) | |
14978–14984 | I believe the else case here is redundant: if RequireCompleteType returns false, the type is complete and there's nothing more you need to do. | |
clang/test/SemaCXX/lambda-invalid-capture.cpp | ||
9–13 | Can you also add a test for the "capturing an array of incomplete type" case please? |
Added a test for the "capturing an array of incomplete type" case. See also responses to inline comments below.
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
14972 | Removed call to getBaseElementType(), changed appearances of EltTy to FieldType instead. | |
14978–14984 | If I just remove the else block, the test case included with the patch keeps crashing. Is there any way a Decl can be invalid even after RequireCompleteType returns false? |
Looks good, thanks! (Though we generally prefer fewer test files with more test per file, because a lot of the overhead of running tests is the setup / teardown time, so can you merge the two added tests into a single file?)
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
14978–14984 | I think I was just wrong before :) Looks like RequireCompleteType doesn't check whether the type is invalid. |
Folded the two test cases (capturing an invalid type and capturing an invalid array type) into a single file.
You'll need to use FieldType->getBaseElementTypeUnsafe() or similar here to handle the case where the field type is an array whose element type is a class. (That can happen in a lambda if you capture a local array variable by value.)