2024-04-08 07:18:11

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] [v2] scripts/unifdef: avoid constexpr keyword

From: Arnd Bergmann <[email protected]>

Starting with c23, 'constexpr' is a keyword in C like in C++ and cannot
be used as an identifier:

scripts/unifdef.c:206:25: error: 'constexpr' can only be used in variable declarations
206 | static bool constexpr; /* constant #if expression */
| ^
scripts/unifdef.c:880:13: error: expected identifier or '('
880 | constexpr = false;
| ^

Rename this instance to allow changing to C23 at some point in the future.

Cc: Masahiro Yamada <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: [email protected]
Reviewed-By: Tony Finch <[email protected]>
Signed-off-by: Arnd Bergmann <[email protected]>
---
v2: include fixup from Tony
---
scripts/unifdef.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index db00e3e30a59..ff15efd6e7d7 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -203,7 +203,7 @@ static int depth; /* current #if nesting */
static int delcount; /* count of deleted lines */
static unsigned blankcount; /* count of blank lines */
static unsigned blankmax; /* maximum recent blankcount */
-static bool constexpr; /* constant #if expression */
+static bool constexpression; /* constant #if expression */
static bool zerosyms = true; /* to format symdepth output */
static bool firstsym; /* ditto */

@@ -819,7 +819,7 @@ static const struct ops {
/*
* Function for evaluating the innermost parts of expressions,
* viz. !expr (expr) number defined(symbol) symbol
- * We reset the constexpr flag in the last two cases.
+ * We reset the constexpression flag in the last two cases.
*/
static Linetype
eval_unary(const struct ops *ops, int *valp, const char **cpp)
@@ -877,7 +877,7 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
cp = skipcomment(cp);
if (defparen && *cp++ != ')')
return (LT_ERROR);
- constexpr = false;
+ constexpression = false;
} else if (!endsym(*cp)) {
debug("eval%d symbol", ops - eval_ops);
sym = findsym(cp);
@@ -895,7 +895,7 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
lt = *valp ? LT_TRUE : LT_FALSE;
cp = skipargs(cp);
}
- constexpr = false;
+ constexpression = false;
} else {
debug("eval%d bad expr", ops - eval_ops);
return (LT_ERROR);
@@ -955,10 +955,10 @@ ifeval(const char **cpp)
int val = 0;

debug("eval %s", *cpp);
- constexpr = killconsts ? false : true;
+ constexpression = killconsts ? false : true;
ret = eval_table(eval_ops, &val, cpp);
debug("eval = %d", val);
- return (constexpr ? LT_IF : ret == LT_ERROR ? LT_IF : ret);
+ return (constexpression ? LT_IF : ret == LT_ERROR ? LT_IF : ret);
}

/*
--
2.39.2



2024-04-10 07:58:51

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH] [v2] scripts/unifdef: avoid constexpr keyword

On Mon, Apr 08, 2024 at 09:17:52AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
>
> Starting with c23, 'constexpr' is a keyword in C like in C++ and cannot
> be used as an identifier:
>
> scripts/unifdef.c:206:25: error: 'constexpr' can only be used in variable declarations
> 206 | static bool constexpr; /* constant #if expression */
> | ^
> scripts/unifdef.c:880:13: error: expected identifier or '('
> 880 | constexpr = false;
> | ^
>
> Rename this instance to allow changing to C23 at some point in the future.
>
> Cc: Masahiro Yamada <[email protected]>
> Cc: Nathan Chancellor <[email protected]>
> Cc: Nicolas Schier <[email protected]>
> Cc: [email protected]
> Reviewed-By: Tony Finch <[email protected]>
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> v2: include fixup from Tony

thanks, LGTM.

Reviewed-by: Nicolas Schier <[email protected]>

2024-04-16 12:09:06

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] [v2] scripts/unifdef: avoid constexpr keyword

On Mon, Apr 8, 2024 at 4:18 PM Arnd Bergmann <[email protected]> wrote:
>
> From: Arnd Bergmann <[email protected]>
>
> Starting with c23, 'constexpr' is a keyword in C like in C++ and cannot
> be used as an identifier:
>
> scripts/unifdef.c:206:25: error: 'constexpr' can only be used in variable declarations
> 206 | static bool constexpr; /* constant #if expression */
> | ^
> scripts/unifdef.c:880:13: error: expected identifier or '('
> 880 | constexpr = false;
> | ^
>
> Rename this instance to allow changing to C23 at some point in the future.
>
> Cc: Masahiro Yamada <[email protected]>
> Cc: Nathan Chancellor <[email protected]>
> Cc: Nicolas Schier <[email protected]>
> Cc: [email protected]
> Reviewed-By: Tony Finch <[email protected]>
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
> v2: include fixup from Tony


Applied to linux-kbuild. Thanks.


> ---
> scripts/unifdef.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/unifdef.c b/scripts/unifdef.c
> index db00e3e30a59..ff15efd6e7d7 100644
> --- a/scripts/unifdef.c
> +++ b/scripts/unifdef.c
> @@ -203,7 +203,7 @@ static int depth; /* current #if nesting */
> static int delcount; /* count of deleted lines */
> static unsigned blankcount; /* count of blank lines */
> static unsigned blankmax; /* maximum recent blankcount */
> -static bool constexpr; /* constant #if expression */
> +static bool constexpression; /* constant #if expression */
> static bool zerosyms = true; /* to format symdepth output */
> static bool firstsym; /* ditto */
>
> @@ -819,7 +819,7 @@ static const struct ops {
> /*
> * Function for evaluating the innermost parts of expressions,
> * viz. !expr (expr) number defined(symbol) symbol
> - * We reset the constexpr flag in the last two cases.
> + * We reset the constexpression flag in the last two cases.
> */
> static Linetype
> eval_unary(const struct ops *ops, int *valp, const char **cpp)
> @@ -877,7 +877,7 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
> cp = skipcomment(cp);
> if (defparen && *cp++ != ')')
> return (LT_ERROR);
> - constexpr = false;
> + constexpression = false;
> } else if (!endsym(*cp)) {
> debug("eval%d symbol", ops - eval_ops);
> sym = findsym(cp);
> @@ -895,7 +895,7 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
> lt = *valp ? LT_TRUE : LT_FALSE;
> cp = skipargs(cp);
> }
> - constexpr = false;
> + constexpression = false;
> } else {
> debug("eval%d bad expr", ops - eval_ops);
> return (LT_ERROR);
> @@ -955,10 +955,10 @@ ifeval(const char **cpp)
> int val = 0;
>
> debug("eval %s", *cpp);
> - constexpr = killconsts ? false : true;
> + constexpression = killconsts ? false : true;
> ret = eval_table(eval_ops, &val, cpp);
> debug("eval = %d", val);
> - return (constexpr ? LT_IF : ret == LT_ERROR ? LT_IF : ret);
> + return (constexpression ? LT_IF : ret == LT_ERROR ? LT_IF : ret);
> }
>
> /*
> --
> 2.39.2
>


--
Best Regards
Masahiro Yamada