diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -969,6 +969,52 @@ HI.Definition = "template using AA = A"; HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T' HI.TemplateParameters = {{{"typename"}, std::string("T"), llvm::None}}; + }}, + {// Constant array + R"cpp( + using m_int = int; + + m_int ^[[arr]][10]; + )cpp", + [](HoverInfo &HI) { + HI.Name = "arr"; + HI.NamespaceScope = ""; + HI.LocalScope = ""; + HI.Kind = index::SymbolKind::Variable; + HI.Definition = "m_int arr[10]"; + HI.Type = {"m_int[10]", "int[10]"}; + }}, + {// Incomplete array + R"cpp( + using m_int = int; + + extern m_int ^[[arr]][]; + )cpp", + [](HoverInfo &HI) { + HI.Name = "arr"; + HI.NamespaceScope = ""; + HI.LocalScope = ""; + HI.Kind = index::SymbolKind::Variable; + HI.Definition = "extern m_int arr[]"; + HI.Type = {"m_int[]", "int[]"}; + }}, + {// Dependent size array + R"cpp( + using m_int = int; + + template + struct Test { + m_int ^[[arr]][Size]; + }; + )cpp", + [](HoverInfo &HI) { + HI.Name = "arr"; + HI.NamespaceScope = ""; + HI.LocalScope = "Test::"; + HI.AccessSpecifier = "public"; + HI.Kind = index::SymbolKind::Field; + HI.Definition = "m_int arr[Size]"; + HI.Type = {"m_int[Size]", "int[Size]"}; }}}; for (const auto &Case : Cases) { SCOPED_TRACE(Case.Code); diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -131,6 +131,38 @@ } } + if (const auto *CAT = dyn_cast(Ty)) { + QualType ElementTy = + desugarForDiagnostic(Context, CAT->getElementType(), ShouldAKA); + QT = Context.getConstantArrayType( + ElementTy, CAT->getSize(), CAT->getSizeExpr(), CAT->getSizeModifier(), + CAT->getIndexTypeCVRQualifiers()); + break; + } + if (const auto *VAT = dyn_cast(Ty)) { + QualType ElementTy = + desugarForDiagnostic(Context, VAT->getElementType(), ShouldAKA); + QT = Context.getVariableArrayType( + ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(), + VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange()); + break; + } + if (const auto *DSAT = dyn_cast(Ty)) { + QualType ElementTy = + desugarForDiagnostic(Context, DSAT->getElementType(), ShouldAKA); + QT = Context.getDependentSizedArrayType( + ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(), + DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange()); + break; + } + if (const auto *IAT = dyn_cast(Ty)) { + QualType ElementTy = + desugarForDiagnostic(Context, IAT->getElementType(), ShouldAKA); + QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(), + IAT->getIndexTypeCVRQualifiers()); + break; + } + // Don't desugar magic Objective-C types. if (QualType(Ty,0) == Context.getObjCIdType() || QualType(Ty,0) == Context.getObjCClassType() || diff --git a/clang/test/Misc/diag-aka-types.cpp b/clang/test/Misc/diag-aka-types.cpp --- a/clang/test/Misc/diag-aka-types.cpp +++ b/clang/test/Misc/diag-aka-types.cpp @@ -62,3 +62,9 @@ void (&f3)(decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'void (decltype(1 + 2))' (aka 'void (int)') cannot bind to a temporary of type 'int'}} decltype(1+2) (&f4)(double, decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'decltype(1 + 2) (double, decltype(1 + 2))' (aka 'int (double, int)') cannot bind to a temporary of type 'int'}} auto (&f5)() -> decltype(1+2) = 0; // expected-error{{non-const lvalue reference to type 'auto () -> decltype(1 + 2)' (aka 'auto () -> int') cannot bind to a temporary of type 'int'}} + +using C = decltype(1+2);; +C a6[10]; +extern C a8[]; +int a9 = a6; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[10]' (aka 'int[10]')}} +int a10 = a8; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[]' (aka 'int[]')}}