Skip to content

False positive MACRO_ARG_PRECEDENCE #43

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

Closed
nshy opened this issue Oct 4, 2022 · 0 comments · Fixed by #44
Closed

False positive MACRO_ARG_PRECEDENCE #43

nshy opened this issue Oct 4, 2022 · 0 comments · Fixed by #44
Assignees
Labels
bug Something isn't working

Comments

@nshy
Copy link
Contributor

nshy commented Oct 4, 2022

And the trigger is:

ERROR: Macro argument 'field' may be better as '(field)' to avoid precedence issues
#141: FILE: src/trivia/util.h:158:
+#define uptr_field_addr(obj, field) \
+	({ \
+		(typeof(&((typeof(obj))0)->field)) \
+			((char *)(obj) + (size_t)&((typeof(obj))0)->field); \
+	})

Using brackets around field won't compile unfortunately.

@nshy nshy self-assigned this Oct 4, 2022
nshy added a commit to nshy/checkpatch that referenced this issue Oct 4, 2022
Example which gives the FP:

  #define uptr_field_addr(obj, field) \
        ({ \
                (typeof(&((typeof(obj))0)->field)) \
                        ((char *)(obj) + (size_t)&((typeof(obj))0)->field); \
        })

  ERROR: Macro argument 'field' may be better as '(field)' to avoid
  precedence issues

And using () around `field` won't compile.

Closes tarantool#43
nshy added a commit to nshy/checkpatch that referenced this issue Oct 4, 2022
Example which gives the FP:

  #define uptr_field_addr(obj, field) \
        ({ \
                (typeof(&((typeof(obj))0)->field)) \
                        ((char *)(obj) + (size_t)&((typeof(obj))0)->field); \
        })

  ERROR: Macro argument 'field' may be better as '(field)' to avoid
  precedence issues

And using () around `field` won't compile.

Closes tarantool#43
@locker locker added the bug Something isn't working label Oct 4, 2022
@locker locker closed this as completed in #44 Oct 4, 2022
locker pushed a commit that referenced this issue Oct 4, 2022
Example which gives the FP:

  #define uptr_field_addr(obj, field) \
        ({ \
                (typeof(&((typeof(obj))0)->field)) \
                        ((char *)(obj) + (size_t)&((typeof(obj))0)->field); \
        })

  ERROR: Macro argument 'field' may be better as '(field)' to avoid
  precedence issues

And using () around `field` won't compile.

Closes #43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants