Improve type printing of size-dependent const arrays to normalize array-of-const and const-array

Follow-on from 2bd8493847 based on
postcommit feedback from Richard Smith.

The VariableArray case I couldn't figure out how to test/provoke - you
can't write/form a variable array in any context other than a local
variable that I know of, and in that case `const int x[n]` is the
normalized form already (array-of-const) and you can't use typedefs
(since you can't typedef int[n] with variable 'n') to force the
const-array AST that would produce the undesirable type printing "int
const [n]".
This commit is contained in:
David Blaikie 2021-09-15 13:37:24 -07:00
parent 4ac4e52189
commit 40acc0adad
2 changed files with 6 additions and 2 deletions

View File

@ -242,13 +242,16 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
break;
case Type::DependentSizedArray:
NeedARCStrongQualifier = true;
LLVM_FALLTHROUGH;
case Type::ConstantArray:
case Type::IncompleteArray:
return canPrefixQualifiers(
cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),
NeedARCStrongQualifier);
case Type::VariableArray:
case Type::DependentSizedArray:
NeedARCStrongQualifier = true;
LLVM_FALLTHROUGH;

View File

@ -23,5 +23,6 @@ class array {
using array_T_size = T[Size];
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T [Size]' dependent <col:25, col:30>
using const_array_T_size = const T[Size];
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T [Size]' dependent <col:37, col:42>
};