Skip to content

Commit 2fb6915

Browse files
author
H. Peter Anvin
committed
compiler_types.h: add "auto" as a macro for "__auto_type"
"auto" was defined as a keyword back in the K&R days, but as a storage type specifier. No one ever used it, since it was and is the default storage type for local variables. C++11 recycled the keyword to allow a type to be declared based on the type of an initializer. This was finally adopted into standard C in C23. gcc and clang provide the "__auto_type" alias keyword as an extension for pre-C23, however, there is no reason to pollute the bulk of the source base with this temporary keyword; instead define "auto" as a macro unless the compiler is running in C23+ mode. This macro is added in <linux/compiler_types.h> because that header is included in some of the tools headers, wheres <linux/compiler.h> is not as it has a bunch of very kernel-specific things in it. [ Cc: stable to reduce potential backporting burden. ] Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Acked-by: Miguel Ojeda <ojeda@kernel.org> Cc: <stable@kernel.org>
1 parent c2f2b01 commit 2fb6915

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

include/linux/compiler_types.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313

1414
#ifndef __ASSEMBLY__
1515

16+
/*
17+
* C23 introduces "auto" as a standard way to define type-inferred
18+
* variables, but "auto" has been a (useless) keyword even since K&R C,
19+
* so it has always been "namespace reserved."
20+
*
21+
* Until at some future time we require C23 support, we need the gcc
22+
* extension __auto_type, but there is no reason to put that elsewhere
23+
* in the source code.
24+
*/
25+
#if __STDC_VERSION__ < 202311L
26+
# define auto __auto_type
27+
#endif
28+
1629
/*
1730
* Skipped when running bindgen due to a libclang issue;
1831
* see https://github.com/rust-lang/rust-bindgen/issues/2244.

0 commit comments

Comments
 (0)