user1621581
user1621581

Reputation: 113

Unused function in macro with clang

I have a macro that is defined as the following, ie:

#define next_position() (bit ? *str++ : (*str++) & 0xff)

warning: expression result unused [-Wunused-value]

Clang is saying the first *str++ is being unused in the macro, but gcc never displayed this 'warning' to me, is this a compiler bug? how can I work around it? It seems like a legitimate warning.

Upvotes: 1

Views: 1086

Answers (1)

ArtemB
ArtemB

Reputation: 3632

Clang is correct -- you are dereferencing str, but are not using its value. If all you want is to advance str, then next_position would boil down to:

#define next_position() str++

It would bring the question why you would want to hide that behind a macro, but that's a different issue.

As for getting warning from clang, but not gcc, they are different compilers. They are detecting overlapping but not identical set of potential issues with the code and they are pedantic in somewhat different ways. Even gcc itself produces different sets of warnings depending on optimization level and gcc version. The fact that one compiler produces a warning but another does not does not necessarily mean that there's a bug in the compiler. Nor does it say anything whether there's really a problem in your code. It's just an indication that something may be off.

Upvotes: 1

Related Questions