]> granicus.if.org Git - clang/commitdiff
Mark that qualifiers can prefix the auto type. This seems to just have
authorChandler Carruth <chandlerc@gmail.com>
Mon, 2 Sep 2013 19:20:06 +0000 (19:20 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 2 Sep 2013 19:20:06 +0000 (19:20 +0000)
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
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp

index 344d12c44f9457dbc1974053e247fc47c4449ef7..ec7559c2f512cd365267890a9d1a83e31a2ca8d8 100644 (file)
@@ -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;
   }
index e566d2a8f1d28a77dd83e8d9e83570dedacd1629..84f9f9b829834305f4dc6e81e1deacbc5a8aaf39 100644 (file)
@@ -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;
 };
index 1f811164145347c56623a81a08d320922cc2d2fd..1711aaa8aef94410f92257d850604d1c4715b9ac 100644 (file)
@@ -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 {
index 6b1f3e438d8f1d988e909bf14bf686d319f06cfd..ce90728861605fed8cf7b9f993c572979ef30a71 100644 (file)
@@ -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())())();
index 4ebbfce289ea174d2e0fa8c9872e3c636a8ef2be..2e99b525b443118a1106c60a323ac7dc664f7ccc 100644 (file)
@@ -11,7 +11,7 @@ void f() {
   only<double*> 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}}
 }