git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] packfile: ensure that enum object_type is defined

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 26, 2018, 00:44 UTC
Message-ID
<20180726004400.GA217613@aiede.svl.corp.google.com>
In-Reply-To
<20180725215607.19910-2-dev+git@drbeat.li>
Beat Bolli wrote:
Show 18 quoted lines
> When compiling under Apple LLVM version 9.1.0 (clang-902.0.39.2) with
> "make DEVELOPER=1 DEVOPTS=pedantic", the compiler says
>
>     error: redeclaration of already-defined enum 'object_type' is a GNU
>     extension [-Werror,-Wgnu-redeclared-enum]
>
> According to https://en.cppreference.com/w/c/language/declarations
> (section "Redeclaration"), a repeated declaration after the definition
> is only legal for structs and unions, but not for enums.
>
> Drop the belated declaration of enum object_type and include cache.h
> instead to make sure the enum is defined.
>
> Helped-by: Jonathan Nieder <jrnieder@gmail.com>
> Signed-off-by: Beat Bolli <dev+git@drbeat.li>
> ---
>  packfile.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks! I had run into this using clang on Linux, too, but hadn't spent the time to track it down and write a patch.

Running
	git grep -e 'enum [^ ]*;'
doesn't find any other instances of this error.  Thanks for fixing it.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
By the way, not about this patch:
[...]
Show 12 quoted lines
> +++ b/packfile.h
> @@ -1,12 +1,12 @@
>  #ifndef PACKFILE_H
>  #define PACKFILE_H
>  
> +#include "cache.h"
>  #include "oidset.h"
>  
>  /* in object-store.h */
>  struct packed_git;
>  struct object_info;
> -enum object_type;

This '/* in object-store.h */' comment can easily go stale since nothing enforces that it stays accurate. I don't think it's a useful comment to have anyway, since it's straightforward to grep for where the struct is defined. I think we should remove the comment.

Thanks, Jonathan

Previous: Beat Bolli
Message 3 of 3 in “Pedantic fix for Apple clang”
  1. 0/1 Pedantic fix for Apple clangBeat Bolli, Jul 25, 2018
  2. packfile: ensure that enum object_type is definedBeat Bolli, Jul 25, 2018
  3. Jonathan NiederJul 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.