diff options
author | Guillot Tony <tony.guillot@protonmail.com> | 2023-10-05 12:14:23 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2023-10-05 12:16:00 -0400 |
commit | 13ffc61a4224012ab1abb4e806d03fc149aec91f (patch) | |
tree | 28dc578270084a7472045534a1ac22818bdda197 /clang/lib/Parse/ParseDecl.cpp | |
parent | 0ca7e609fc5ebdd9c95f6cba3c608cae4b575846 (diff) | |
download | llvm-13ffc61a4224012ab1abb4e806d03fc149aec91f.zip llvm-13ffc61a4224012ab1abb4e806d03fc149aec91f.tar.gz llvm-13ffc61a4224012ab1abb4e806d03fc149aec91f.tar.bz2 |
[C2X] N3007 Type inference for object definitions
Re-landing 5d78b78c8538 which was reverted.
This patches implements the auto keyword from the N3007 standard
specification.
This allows deducing the type of the variable like in C++:
```
auto nb = 1;
auto chr = 'A';
auto str = "String";
```
The list of statements which allows the usage of auto:
* Basic variables declarations (int, float, double, char, char*...)
* Macros declaring a variable with the auto type
The list of statements which will not work with the auto keyword:
* auto arrays
* sizeof(), alignas()
* auto parameters, auto return type
* auto as a struct/typedef member
* uninitialized auto variables
* auto in an union
* auto as a enum type specifier
* auto casts
* auto in an compound literals
Differential Revision: https://reviews.llvm.org/D133289
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 9351594..bcc70c0 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4038,7 +4038,7 @@ void Parser::ParseDeclarationSpecifiers( isStorageClass = true; break; case tok::kw_auto: - if (getLangOpts().CPlusPlus11) { + if (getLangOpts().CPlusPlus11 || getLangOpts().C23) { if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc, PrevSpec, DiagID, Policy); |