From 39093279f2ede4af9048b89d048d7fe9182a50f8 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 12 Oct 2021 15:24:05 -0700 Subject: [PATCH] Improve printing of const variable sized arrays Follow-on from 40acc0adad59ac39e9a7a02fcd93161298500c00 with help from Richard Smith on how to provoke this particular case. --- clang/lib/AST/TypePrinter.cpp | 4 +--- clang/test/Sema/vla.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 clang/test/Sema/vla.cpp diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 3c7a6b8..e573037 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -242,6 +242,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType(); break; + case Type::VariableArray: case Type::DependentSizedArray: NeedARCStrongQualifier = true; LLVM_FALLTHROUGH; @@ -251,9 +252,6 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, return canPrefixQualifiers( cast(UnderlyingType)->getElementType().getTypePtr(), NeedARCStrongQualifier); - case Type::VariableArray: - NeedARCStrongQualifier = true; - LLVM_FALLTHROUGH; case Type::Adjusted: case Type::Decayed: diff --git a/clang/test/Sema/vla.cpp b/clang/test/Sema/vla.cpp new file mode 100644 index 0000000..b4416a0 --- /dev/null +++ b/clang/test/Sema/vla.cpp @@ -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]')}} +} -- 2.7.4