From 4d4032206c9f966d991c73000e8816b910fb2fd7 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 2 Sep 2013 19:20:06 +0000 Subject: [PATCH] Mark that qualifiers can prefix the auto type. This seems to just have been an oversight, as it definitely works. Every test which changed had the const written on the LHS of the auto already. Notably, this also makes things like cpp11-migrate's formation of 'const auto &' variables much more familiar. Yes, many people feel that 'const' and other qualifiers belong on the RHS of the type. I'm not going to argue about that because Clang already *overwhelming* places the qualifiers on the LHS when it can and on the RHS when it must. We shouldn't diverge for auto. We should add a tool to clang-tidy that fixes this in either direction, and then wire up clang-tidy to tools like cpp11-migrate to fix their placement after transforms. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189769 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/TypePrinter.cpp | 2 +- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp | 2 +- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp | 2 +- test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp | 2 +- test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 344d12c44f..ec7559c2f5 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -167,6 +167,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, TC = Subst->getReplacementType()->getTypeClass(); switch (TC) { + case Type::Auto: case Type::Builtin: case Type::Complex: case Type::UnresolvedUsing: @@ -217,7 +218,6 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, case Type::Attributed: case Type::PackExpansion: case Type::SubstTemplateTypeParm: - case Type::Auto: CanPrefixQualifiers = false; break; } diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp index e566d2a8f1..84f9f9b829 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp @@ -35,7 +35,7 @@ class X { }; struct S { - static const auto a; // expected-error {{declaration of variable 'a' with type 'auto const' requires an initializer}} + static const auto a; // expected-error {{declaration of variable 'a' with type 'const auto' requires an initializer}} static const auto b = 0; static const int c; }; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp index 1f81116414..1711aaa8ae 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp @@ -55,7 +55,7 @@ void f() { auto *fail1 = 0; // expected-error {{variable 'fail1' with type 'auto *' has incompatible initializer of type 'int'}} int **p; - const auto **fail2(p); // expected-error {{variable 'fail2' with type 'auto const **' has incompatible initializer of type 'int **'}} + const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}} } struct S { diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp index 6b1f3e438d..ce90728861 100644 --- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s auto a() -> int; // ok -const auto b() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'auto const'}} +const auto b() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'const auto'}} auto *c() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'auto *'}} auto (d() -> int); // expected-error {{trailing return type may not be nested within parentheses}} auto e() -> auto (*)() -> auto (*)() -> void; // ok: same as void (*(*e())())(); diff --git a/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp b/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp index 4ebbfce289..2e99b525b4 100644 --- a/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp +++ b/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp @@ -11,7 +11,7 @@ void f() { only q = new (auto) (0.0); new auto; // expected-error{{new expression for type 'auto' requires a constructor argument}} - new (const auto)(); // expected-error{{new expression for type 'auto const' requires a constructor argument}} + new (const auto)(); // expected-error{{new expression for type 'const auto' requires a constructor argument}} new (auto) (1,2,3); // expected-error{{new expression for type 'auto' contains multiple constructor arguments}} } -- 2.50.1