Fix grammar in diagnostic for wrong arity in a structured binding.

This commit is contained in:
Richard Smith 2021-01-13 17:40:22 -08:00
parent dfc1901d51
commit cd4c55c974
3 changed files with 24 additions and 6 deletions

View File

@ -470,8 +470,9 @@ def err_decomp_decl_not_alone : Error<
def err_decomp_decl_requires_init : Error<
"decomposition declaration %0 requires an initializer">;
def err_decomp_decl_wrong_number_bindings : Error<
"type %0 decomposes into %2 elements, but %select{only |}3%1 "
"names were provided">;
"type %0 decomposes into %3 %plural{1:element|:elements}2, but "
"%select{%plural{0:no|:only %1}1|%1}4 "
"%plural{1:name was|:names were}1 provided">;
def err_decomp_decl_unbindable_type : Error<
"cannot decompose %select{union|non-class, non-array}1 type %2">;
def err_decomp_decl_multiple_bases_with_members : Error<

View File

@ -902,7 +902,8 @@ static bool checkSimpleDecomposition(
llvm::function_ref<ExprResult(SourceLocation, Expr *, unsigned)> GetInit) {
if ((int64_t)Bindings.size() != NumElems) {
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size() << NumElems.toString(10)
<< DecompType << (unsigned)Bindings.size()
<< (unsigned)NumElems.getLimitedValue(UINT_MAX) << NumElems.toString(10)
<< (NumElems < Bindings.size());
return true;
}
@ -1148,8 +1149,9 @@ static bool checkTupleLikeDecomposition(Sema &S,
const llvm::APSInt &TupleSize) {
if ((int64_t)Bindings.size() != TupleSize) {
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size() << TupleSize.toString(10)
<< (TupleSize < Bindings.size());
<< DecompType << (unsigned)Bindings.size()
<< (unsigned)TupleSize.getLimitedValue(UINT_MAX)
<< TupleSize.toString(10) << (TupleSize < Bindings.size());
return true;
}
@ -1373,7 +1375,7 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
[](FieldDecl *FD) { return !FD->isUnnamedBitfield(); });
assert(Bindings.size() != NumFields);
S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
<< DecompType << (unsigned)Bindings.size() << NumFields
<< DecompType << (unsigned)Bindings.size() << NumFields << NumFields
<< (NumFields < Bindings.size());
return true;
};

View File

@ -4,6 +4,21 @@ void use_from_own_init() {
auto [a] = a; // expected-error {{binding 'a' cannot appear in the initializer of its own decomposition declaration}}
}
void num_elems() {
struct A0 {} a0;
int a1[1], a2[2];
auto [] = a0; // expected-warning {{does not allow a decomposition group to be empty}}
auto [v1] = a0; // expected-error {{type 'A0' decomposes into 0 elements, but 1 name was provided}}
auto [] = a1; // expected-error {{type 'int [1]' decomposes into 1 element, but no names were provided}} expected-warning {{empty}}
auto [v2] = a1;
auto [v3, v4] = a1; // expected-error {{type 'int [1]' decomposes into 1 element, but 2 names were provided}}
auto [] = a2; // expected-error {{type 'int [2]' decomposes into 2 elements, but no names were provided}} expected-warning {{empty}}
auto [v5] = a2; // expected-error {{type 'int [2]' decomposes into 2 elements, but only 1 name was provided}}
auto [v6, v7] = a2;
auto [v8, v9, v10] = a2; // expected-error {{type 'int [2]' decomposes into 2 elements, but 3 names were provided}}
}
// As a Clang extension, _Complex can be decomposed.
float decompose_complex(_Complex float cf) {
static _Complex float scf;