Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ares__iface_ip_flags_t cannot have the value 0. #723

Open
dzalyalov88 opened this issue Mar 11, 2024 · 8 comments
Open

ares__iface_ip_flags_t cannot have the value 0. #723

dzalyalov88 opened this issue Mar 11, 2024 · 8 comments

Comments

@dzalyalov88
Copy link

0 is not a possible value for ares__iface_ip_flags_t, but in several places, it takes this value:

  1. return 0; (ares__iface_ips.c:257)
  2. ares__iface_ip_flags_t addrflag = 0; (ares__iface_ips.c:355)
  3. ares__iface_ip_flags_t addrflag = 0; (ares__iface_ips.c:450)
@dzalyalov88 dzalyalov88 changed the title ares__iface_ip_flags_t cannot has the value 0. ares__iface_ip_flags_t cannot have the value 0. Mar 11, 2024
@bradh352
Copy link
Member

bradh352 commented Mar 11, 2024

Is this actually emitting some warning somewhere ? This is valid in C to use an enum as a flags value, however C++ doesn't allow this. Are you trying to compile c-ares as C++ code?

@dzalyalov88
Copy link
Author

yes, this warning caused a compilation issue:
"error: integer constant not in range of enumerated type 'ares__iface_ip_flags_t' [-Werror,-Wassign-enum]"

@dzalyalov88
Copy link
Author

Before the last changes, c-ares was C++ compatible. And I hope it will be the same in the future.

@bradh352
Copy link
Member

bradh352 commented Mar 12, 2024

I'm not sure I understand why you'd compile C code with a C++ compiler, can you provide the reason why this is desirable? Is this some limitation of some embedded environment? Or are you just compiling with a warning flag to force this behavior?

@bradh352
Copy link
Member

Looking at it -Wassign-enum only talks about integer constants, so if we define a NONE value of 0 for the flags, the issue would go away, it doesn't look like it warns on combining enum values as flags according to the docs. If that's the case and you're not actually using a C++ compiler to compile C code, then that would fix it rather than using a different type.

@bradh352
Copy link
Member

Just tested it, it does warn when you combine 2 enum values as flags:

[74/92] Building C object src/lib/CMakeFiles/c-ares.dir/ares_strsplit.c.o
/Users/bhouse/svn/c-ares/src/lib/ares_strsplit.c:97:34: warning: integer constant not in range of enumerated type 'ares__buf_split_t' [-Wassign-enum]
    ARES_BUF_SPLIT_NO_DUPLICATES | ARES_BUF_SPLIT_CASE_INSENSITIVE, &llist);

@dzalyalov88
Copy link
Author

I have checked our code.
We are using the clang compiler with the parameters -Wassign-enum and -Werror

@bradh352
Copy link
Member

Can this warning flag be excluded, or at least be excluded from -Werror in your project? That's a non-standard flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants