rsandifo-arm created this revision. rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall. Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett. Herald added a project: clang. rsandifo-arm added a parent revision: D75737: [Sema][SVE] Don't allow fields to have sizeless type.
Since fields can't have sizeless type, it also doesn't make sense to capture sizeless types by value in lambda expressions. This patch makes sure that we diagnose that and that we use "sizeless type" rather "incomplete type" in the associated message. (Both are correct, but "sizeless type" is more specific and hopefully more user-friendly.) Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D75738 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/sizeless-1.cpp Index: clang/test/SemaCXX/sizeless-1.cpp =================================================================== --- clang/test/SemaCXX/sizeless-1.cpp +++ clang/test/SemaCXX/sizeless-1.cpp @@ -496,6 +496,7 @@ local_int8 = ([]() -> svint8_t { return svint8_t(); })(); auto fn1 = [&local_int8](svint8_t x) { local_int8 = x; }; auto fn2 = [&local_int8](svint8_t *ptr) { *ptr = local_int8; }; + auto fn3 = [local_int8](svint8_t *ptr) { *ptr = local_int8; }; // expected-error {{by-copy capture of variable 'local_int8' with sizeless type 'svint8_t'}} for (auto x : local_int8) { // expected-error {{no viable 'begin' function available}} } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -16341,9 +16341,10 @@ // Make sure that by-copy captures are of a complete and non-abstract type. if (!Invalid && BuildAndDiagnose) { if (!CaptureType->isDependentType() && - S.RequireCompleteType(Loc, CaptureType, - diag::err_capture_of_incomplete_type, - Var->getDeclName())) + S.RequireCompleteSizedType( + Loc, CaptureType, + diag::err_capture_of_incomplete_or_sizeless_type, + Var->getDeclName())) Invalid = true; else if (S.RequireNonAbstractType(Loc, CaptureType, diag::err_capture_of_abstract_type)) Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1474,8 +1474,8 @@ def err_array_of_abstract_type : Error<"array of abstract class type %0">; def err_capture_of_abstract_type : Error< "by-copy capture of value of abstract type %0">; -def err_capture_of_incomplete_type : Error< - "by-copy capture of variable %0 with incomplete type %1">; +def err_capture_of_incomplete_or_sizeless_type : Error< + "by-copy capture of variable %0 with %select{incomplete|sizeless}1 type %2">; def err_capture_default_non_local : Error< "non-local lambda expression cannot have a capture-default">;
Index: clang/test/SemaCXX/sizeless-1.cpp =================================================================== --- clang/test/SemaCXX/sizeless-1.cpp +++ clang/test/SemaCXX/sizeless-1.cpp @@ -496,6 +496,7 @@ local_int8 = ([]() -> svint8_t { return svint8_t(); })(); auto fn1 = [&local_int8](svint8_t x) { local_int8 = x; }; auto fn2 = [&local_int8](svint8_t *ptr) { *ptr = local_int8; }; + auto fn3 = [local_int8](svint8_t *ptr) { *ptr = local_int8; }; // expected-error {{by-copy capture of variable 'local_int8' with sizeless type 'svint8_t'}} for (auto x : local_int8) { // expected-error {{no viable 'begin' function available}} } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -16341,9 +16341,10 @@ // Make sure that by-copy captures are of a complete and non-abstract type. if (!Invalid && BuildAndDiagnose) { if (!CaptureType->isDependentType() && - S.RequireCompleteType(Loc, CaptureType, - diag::err_capture_of_incomplete_type, - Var->getDeclName())) + S.RequireCompleteSizedType( + Loc, CaptureType, + diag::err_capture_of_incomplete_or_sizeless_type, + Var->getDeclName())) Invalid = true; else if (S.RequireNonAbstractType(Loc, CaptureType, diag::err_capture_of_abstract_type)) Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1474,8 +1474,8 @@ def err_array_of_abstract_type : Error<"array of abstract class type %0">; def err_capture_of_abstract_type : Error< "by-copy capture of value of abstract type %0">; -def err_capture_of_incomplete_type : Error< - "by-copy capture of variable %0 with incomplete type %1">; +def err_capture_of_incomplete_or_sizeless_type : Error< + "by-copy capture of variable %0 with %select{incomplete|sizeless}1 type %2">; def err_capture_default_non_local : Error< "non-local lambda expression cannot have a capture-default">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits