Clang-Tidy complaint about re_snprintf
Closed this issue · 10 comments
Android Studio Clang-Tidy complains about all re_snprintf calls. Example is below. Is this a bug in Clang-Tidy or a real issue with the macro?
Clang-Tidy: Conditional operator with identical true and false expressions
Declared in: re_fmt. h
Definition:
#define re_snprintf(str, size, fmt, ...) \
_re_snprintf_s((str), (size), (fmt), RE_VA_ARGS(__VA_ARGS__))
Replacement:
_re_snprintf_s((event_buf), (sizeof event_buf), ("call closed,%s,%s"),
_Generic((0) ? (prm) : (prm),
_Bool: sizeof(int),
char: sizeof(int),
unsigned char: sizeof(unsigned int),
short: sizeof(int),
unsigned short: sizeof(unsigned int),
int: sizeof(int),
unsigned int: sizeof(unsigned int),
long: sizeof(long),
unsigned long: sizeof(unsigned long),
long long: sizeof(long long),
unsigned long long: sizeof(unsigned long long),
float: sizeof(double),
double: sizeof(double),
char const *: sizeof(char const *),
char *: sizeof(char *),
void const *: sizeof(void const *),
void *: sizeof(void *),
struct pl: sizeof(struct pl),
default: sizeof(void *)),
(prm),
_Generic((0) ? (tone) : (tone),
_Bool: sizeof(int),
char: sizeof(int),
unsigned char: sizeof(unsigned int),
short: sizeof(int),
unsigned short: sizeof(unsigned int),
int: sizeof(int),
unsigned int: sizeof(unsigned int),
long: sizeof(long),
unsigned long: sizeof(unsigned long),
long long: sizeof(long long),
unsigned long long: sizeof(unsigned long long),
float: sizeof(double),
double: sizeof(double),
char const *: sizeof(char const *),
char *: sizeof(char *),
void const *: sizeof(void const *),
void *: sizeof(void *),
struct pl: sizeof(struct pl),
default: sizeof(void *)),
(tone), 0)
This is a false positive and a needed workaround for some compilers.
So is your suggestion that I open an Android Studio ticket about this?
Here are the details:
#1110
https://gcc.gnu.org/legacy-ml/gcc/2016-02/msg00266.html
But since it's a gcc bug/workaround, I'm unsure if there is a real fix for clang-tidy.
Maybe a // NOLINT
for clang-tidy is a option. but unsure how it have to look like and it works for this macro.
I created Android Studio ticket, but usually they don't lead to anything.
I got reply from Android Studio to my ticket:
I see the following in the macro definition:
_Generic((0) ? (prm) : (prm)
Which is a conditional operator, and it has prm on both sides. Clang-Tidy warning seems reasonable to me.
If I replace that line with:
_Generic((prm)
Then the Clang-Tidy warning disappears. I don't know what purpose that ternary operator serves.
So why can't the macro definition be changed like proposed?
I'm on the road. Will try when somewhere.