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.

llvm-svn: 189769
This commit is contained in:
Chandler Carruth 2013-09-02 19:20:06 +00:00
parent 01cb19f93c
commit b4a4326824
5 changed files with 5 additions and 5 deletions

View 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;
}

View 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;
};

View 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 {

View 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())())();

View 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}}
}