Improve printing of const variable sized arrays

Follow-on from 40acc0adad with help from
Richard Smith on how to provoke this particular case.
This commit is contained in:
David Blaikie 2021-10-12 15:24:05 -07:00
parent c0a6381e49
commit 39093279f2
2 changed files with 7 additions and 3 deletions

View File

@ -242,6 +242,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType(); T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
break; break;
case Type::VariableArray:
case Type::DependentSizedArray: case Type::DependentSizedArray:
NeedARCStrongQualifier = true; NeedARCStrongQualifier = true;
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
@ -251,9 +252,6 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
return canPrefixQualifiers( return canPrefixQualifiers(
cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(), cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),
NeedARCStrongQualifier); NeedARCStrongQualifier);
case Type::VariableArray:
NeedARCStrongQualifier = true;
LLVM_FALLTHROUGH;
case Type::Adjusted: case Type::Adjusted:
case Type::Decayed: case Type::Decayed:

6
clang/test/Sema/vla.cpp Normal file
View File

@ -0,0 +1,6 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only
void f1(int n) {
typedef int x[n];
const x y; // expected-error {{default initialization of an object of const type 'const x' (aka 'const int [n]')}}
}