[libcamera-devel] Introduce -Wextra-semi to libcamera

Tomi Valkeinen tomi.valkeinen at iki.fi
Thu Oct 22 08:20:42 CEST 2020


On 22/10/2020 02:00, Laurent Pinchart wrote:

>> A matter of taste, and strictly speaking not part of this series, but I think the macros should not
>> contain the semicolon (e.g. LOG_DECLARE_CATEGORY does), and the semicolon should be where the macro
>> is used. I believe this is the style followed by the kernel (e.g. EXPORT_SYMBOL, DEFINE_MUTEX, ...).
>>
>> I don't know if there are technical reasons either way, but when reading code, my brain flags lines
>> without semicolon as errors =).
> 
> One issue is that sometimes macros expand to functions, and thus don't
> need to be followed by a semicolon. For instance, we have
> 
> #define TEST_REGISTER(klass)                                            \
> int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])      \
> {                                                                       \
>         return klass().execute();                                       \
> }
> 
> so writing
> 
> TEST_REGISTER(...);
> 
> will always be flagged by -Wextra-semi.

I look at this from a bit different perspective. I think -Wextra-semi is not a very good warning.
Afaik there are no cases where extra semicolons could cause any code issues (when placed at
"sensible" places), so extra semicolon is a matter of style, not something to warn about by the
compiler.

I still do like to get rid of extra semicolons, but as it's a matter of style, I'd argue that

TEST_REGISTER(...);

does not have an extra semicolon, even if technically, after pre-processing, it has. And, as the
above line looks like a statement, its style should match that of statements and thus have a semicolon.

Then again, I can't find any tool that checks it as I describe above.

 Tomi


More information about the libcamera-devel mailing list