bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pacify -Wmissing-variable-declarations in unit tests.


From: Collin Funk
Subject: Re: Pacify -Wmissing-variable-declarations in unit tests.
Date: Sun, 28 Apr 2024 04:03:22 -0700
User-agent: Mozilla Thunderbird

Hi Bruno,

On 4/28/24 3:11 AM, Bruno Haible wrote:
>> Can I apply the attached patch which adds the 'static' specifier to
>> global variables in unit tests?
> 
> No! While adding 'static' would be no harm in some tests (such as
> tests/jit/test-cache.c, tests/test-argp-version-etc.c, tests/test-argp.c),
> in other tests the purpose of the global variables is to defeat compiler
> optimizations.
> Maybe in 10 years, everything will be compiled with '-flto' and thus
> compiler optimizations on global variables will be the same as on 'static'
> variables. But we're not there yet, and thus it helps us avoid compiler
> optimizations that would make the unit test a no-op.

I see. It looks like I didn't spend enough time reading GCC's
optimization documentation or I would have known it was a silly
idea...

> (You just discovered how tedious it is to investigate a compiler's
> behaviour that causes a test failure. A compiler optimization that turns
> a unit test into a no-op is even worse: You then notice, by chance, that
> the unit test has not been effective for two years or so...)

Yes, that doesn't sound very fun. I have a feeling you have had that
happen before?

> Recall that [1]
>   Many GCC warning options usually don’t point to mistakes in the code;
>   these warnings enforce a certain programming style.

Yes, good point. So I guess here the warning wants you to be explicit
about the visibility of the symbol. I think ISO C uses the terms
internal/external linkage.

> Yup, this is a programming style.
>   - Other developers do it differently.
>   - In many test cases, this programming style invites the compiler
>     to cause trouble.
> 
> Therefore it's not the programming style that we use in the tests.

Makes sense. Thanks for the explanations.

I will listen to the Makefile and *ignore* them now, or disable them
if they start annoying me. :)

Collin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]