[clang] 3909327 - Improve printing of const variable sized arrays
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 12 19:05:01 PDT 2021
Author: David Blaikie
Date: 2021-10-12T19:04:53-07:00
New Revision: 39093279f2ede4af9048b89d048d7fe9182a50f8
URL: https://github.com/llvm/llvm-project/commit/39093279f2ede4af9048b89d048d7fe9182a50f8
DIFF: https://github.com/llvm/llvm-project/commit/39093279f2ede4af9048b89d048d7fe9182a50f8.diff
LOG: Improve printing of const variable sized arrays
Follow-on from 40acc0adad59ac39e9a7a02fcd93161298500c00 with help from
Richard Smith on how to provoke this particular case.
Added:
clang/test/Sema/vla.cpp
Modified:
clang/lib/AST/TypePrinter.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3c7a6b8b9e95..e573037db10e 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<ArrayType>(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 000000000000..b4416a07cf0e
--- /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]')}}
+}
More information about the cfe-commits
mailing list