From Appmethod Topics
Jump to: navigation, search

Go Up to Keywords, Alphabetical Listing Index

The auto keyword has been redefined in the C++11 standard. Thus, Appmethod C++ supports two different definitions of auto, determined by the standard that each C++ compiler follows.

This page describes both definitions of auto.

C++0x Definition


Storage Class Specifiers


[auto] <data-definition> ;


Use the auto modifier to define a local variable as having a local lifetime.

This is the default for local variables and is rarely used.


void f() {
        auto int x;

C++11 Definition


Type Specifiers


[auto] <variable_name> = <initializer_expression> ;


Use auto as a simple type specifier that deduces its semantics from the initializer expression.


int f() {
        return 1;

int _tmain(int argc, _TCHAR* argv[]) {
        auto x = f();
        return 0;

In this example, the type of the variable x is deduced from its initializer expression: f(). Therefore, x would be of type int, the type returned by f().

Code Migration Issue

When Clang-enhanced C++ compilers encounter old auto syntax (that is, auto used as a storage class specifier), they raise the following warning:

[<compiler> Warning] File1.cpp(12): 'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases.

See Also