git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] parseopt: move definition of enum parse_opt_result up
@ 2019-08-20 18:49 René Scharfe
  2019-08-22 14:47 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-08-20 18:49 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Johannes Schindelin

Define enum parse_opt_result before using it in a typedef.  This avoids
the following compiler warning:

   ./parse-options.h:53:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]
   typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
                ^

While GCC and Clang both accept such a forward reference by default,
other compilers might be less forgiving.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 parse-options.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/parse-options.h b/parse-options.h
index a4bd40bb6a..38a33a087e 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -46,6 +46,15 @@ enum parse_opt_option_flags {
 	PARSE_OPT_COMP_ARG = 1024
 };

+enum parse_opt_result {
+	PARSE_OPT_COMPLETE = -3,
+	PARSE_OPT_HELP = -2,
+	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
+	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
+	PARSE_OPT_NON_OPTION,
+	PARSE_OPT_UNKNOWN
+};
+
 struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);

@@ -241,15 +250,6 @@ const char *optname(const struct option *opt, int flags);

 /*----- incremental advanced APIs -----*/

-enum parse_opt_result {
-	PARSE_OPT_COMPLETE = -3,
-	PARSE_OPT_HELP = -2,
-	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
-	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
-	PARSE_OPT_NON_OPTION,
-	PARSE_OPT_UNKNOWN
-};
-
 /*
  * It's okay for the caller to consume argv/argc in the usual way.
  * Other fields of that structure are private to parse-options and should not
--
2.23.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] parseopt: move definition of enum parse_opt_result up
  2019-08-20 18:49 [PATCH] parseopt: move definition of enum parse_opt_result up René Scharfe
@ 2019-08-22 14:47 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2019-08-22 14:47 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 1890 bytes --]

Hi,

On Tue, 20 Aug 2019, René Scharfe wrote:

> Define enum parse_opt_result before using it in a typedef.  This avoids
> the following compiler warning:
>
>    ./parse-options.h:53:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]
>    typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
>                 ^
>
> While GCC and Clang both accept such a forward reference by default,
> other compilers might be less forgiving.

Looks obviously correct to me.

Thanks,
Dscho

>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  parse-options.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/parse-options.h b/parse-options.h
> index a4bd40bb6a..38a33a087e 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -46,6 +46,15 @@ enum parse_opt_option_flags {
>  	PARSE_OPT_COMP_ARG = 1024
>  };
>
> +enum parse_opt_result {
> +	PARSE_OPT_COMPLETE = -3,
> +	PARSE_OPT_HELP = -2,
> +	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
> +	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
> +	PARSE_OPT_NON_OPTION,
> +	PARSE_OPT_UNKNOWN
> +};
> +
>  struct option;
>  typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
>
> @@ -241,15 +250,6 @@ const char *optname(const struct option *opt, int flags);
>
>  /*----- incremental advanced APIs -----*/
>
> -enum parse_opt_result {
> -	PARSE_OPT_COMPLETE = -3,
> -	PARSE_OPT_HELP = -2,
> -	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
> -	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
> -	PARSE_OPT_NON_OPTION,
> -	PARSE_OPT_UNKNOWN
> -};
> -
>  /*
>   * It's okay for the caller to consume argv/argc in the usual way.
>   * Other fields of that structure are private to parse-options and should not
> --
> 2.23.0
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-22 14:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 18:49 [PATCH] parseopt: move definition of enum parse_opt_result up René Scharfe
2019-08-22 14:47 ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).