Improve printing of const variable sized arrays
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 12 Oct 2021 22:24:05 +0000 (15:24 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 13 Oct 2021 02:04:53 +0000 (19:04 -0700)
Follow-on from 40acc0adad59ac39e9a7a02fcd93161298500c00 with help from
Richard Smith on how to provoke this particular case.

clang/lib/AST/TypePrinter.cpp
clang/test/Sema/vla.cpp [new file with mode: 0644]

index 3c7a6b8..e573037 100644 (file)
@@ -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 (file)
index 0000000..b4416a0
--- /dev/null
@@ -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]')}}
+}