diff options
author | Guillot Tony <tony.guillot@protonmail.com> | 2023-10-05 08:08:37 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2023-10-05 08:11:02 -0400 |
commit | 5d78b78c853830516e734cfa64bfba70479e35dc (patch) | |
tree | 2e4862b41f81c5332b9158619418c37d126d6ed1 /clang/lib/Sema/DeclSpec.cpp | |
parent | 58678d3bcf32bada15d6286dff4abfdbf40bfc21 (diff) | |
download | llvm-5d78b78c853830516e734cfa64bfba70479e35dc.zip llvm-5d78b78c853830516e734cfa64bfba70479e35dc.tar.gz llvm-5d78b78c853830516e734cfa64bfba70479e35dc.tar.bz2 |
[C2X] N3007 Type inference for object definitions
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/Sema/DeclSpec.cpp')
-rw-r--r-- | clang/lib/Sema/DeclSpec.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index 2d0d575..781f24c 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -1375,8 +1375,9 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) { StorageClassSpecLoc = SourceLocation(); } // Diagnose if we've recovered from an ill-formed 'auto' storage class - // specifier in a pre-C++11 dialect of C++. - if (!S.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto) + // specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C. + if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 && + TypeSpecType == TST_auto) S.Diag(TSTLoc, diag::ext_auto_type_specifier); if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 && StorageClassSpec == SCS_auto) |