r189769 - Mark that qualifiers can prefix the auto type. This seems to just have

Chandler Carruth chandlerc at gmail.com
Mon Sep 2 12:20:06 PDT 2013


Author: chandlerc
Date: Mon Sep  2 14:20:06 2013
New Revision: 189769

URL: http://llvm.org/viewvc/llvm-project?rev=189769&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/TypePrinter.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
    cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=189769&r1=189768&r2=189769&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Sep  2 14:20:06 2013
@@ -167,6 +167,7 @@ bool TypePrinter::canPrefixQualifiers(co
     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(co
     case Type::Attributed:
     case Type::PackExpansion:
     case Type::SubstTemplateTypeParm:
-    case Type::Auto:
       CanPrefixQualifiers = false;
       break;
   }

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp?rev=189769&r1=189768&r2=189769&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp Mon Sep  2 14:20:06 2013
@@ -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;
 };

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp?rev=189769&r1=189768&r2=189769&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp Mon Sep  2 14:20:06 2013
@@ -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 {

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp?rev=189769&r1=189768&r2=189769&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp Mon Sep  2 14:20:06 2013
@@ -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())())();

Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp?rev=189769&r1=189768&r2=189769&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp Mon Sep  2 14:20:06 2013
@@ -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}}
 }
 





More information about the cfe-commits mailing list