|
Boost : |
Subject: Re: [boost] Compiler Warnings Tests
From: Vicente Botet Escriba (vicente.botet_at_[hidden])
Date: 2009-11-28 12:08:00
Robert Ramey wrote:
>
> Paul A. Bristow wrote:
>> And I'm starting a new thread for Compiler Warnings Tests
>>
>> The Microsoft docs examples might be a good start?
>>
>> // C4244_level4.cpp
>> // compile with: /W4 == actually warnings = all
>>
>> (warnings = errors will allow normal fail testing if it isn;t
>> possible to check for warnings?)
>>
>> // AND MS extensions off?
>>
>> int aa;
>> unsigned short bb;
>>
>> int main() {
>> int b = 0, c = 0;
>> short a = b + c; // C4244
>>
>> bb += c; // C4244
>> bb = bb + c; // C4244
>> bb += static_cast<unsigned short>(aa); // C4244
>> bb = bb + static_cast<unsigned short>(aa); // OK
>> }
>>
>> So are you proposing a collection of these, with versions that should
>> compile and others that should not, for example:
>>
>> int main()
>> {
>> int b = 0, c = 0;
>> short a = b + c; // C4244
>> }
>>
>> and another with
>>
>> int main()
>> {
>> int b = 0, c = 0;
>> short a = static_cast<short>(b + c); // OK - NO C4244
>> }
>>
>> all run by a jamfile.v2.
>>
>> Or am I still misunderstanding you?
>
> You've got it.
>
> The only difference would be that the warning shouldn't be associated with
> a
> particular compiler.
>
> Look at boost/libs/config tests for inspiriation. Tests would be
> something
> like:
>
> boost/libs/warnings/
> test_data_truncation
> // this would correspond to C4244 for ms and ? for other ones
> // this test would be "compile-pass"
> // and it would contain a number of tests cases
>
> test_unused_argument
> test_argument_name_shadowing
> test_virtual_dtor_missing
> test_cant_create_default_construtor
> test_cant_create_default_assignment
> ...
>
>
> On the boost testing matrix, the first row describes the environment.
> To make this useful, this test should be run with the first row -
> environment description including the warning level.
>
> Note that I use my library_test.sh to run tests for one specific
> library. This creates an html test matrix on your local machine
> which shows all the warning emitted. The beauty of this
> system is that it's very easy to run the tests and create the
> test matrix on your local machine for just one library.
>
> Robert Ramey
>
>
Hi,
I second the point of view that the test case shouldn't be associated with a
particular compiler. But I have some comments on this. Here is how I see the
compiler warning tests:
We need to have a test that probes the warning is present for some
compilers. The simple way is to build with warnigs_as_errors=on and check
that the compilation fails.
We need of course check that the workaround or a better coding style solves
the issue. This needs to be done also with warnigs_as_errors=on and check
that the compilation succeeds.
And last, in some cases, we need to check that with warnigs_as_errors=off
both are equivalent. This needs to be done with warnigs_as_errors=off and
check the test run succeed.
int main() {
int b = 30000, c = 30000;
#if defined(BOOST_WARNING_AS_ERROR_MUST_FAIL)
short a = b + c; // C4244
#elif undefined(BOOST_WARNING_AS_ERROR_MUST_SUCCEED)
short a = static_cast<unsigned short>(b + c);
#else
short a1 = b + c; // C4244
short a2 = static_cast<unsigned short>(b + c);
assert(a1==a2)
#endif
}
[Note: The following should not correspond to the bjam syntax]
[ compile_fails test_data_truncation.cpp : : warnigs_as_errors=on
define=BOOST_WARNING_AS_ERROR_MUST_FAIL :
test_data_truncation_warning_as_errors_must_fail ]
[ compile test_data_truncation.cpp : : warnigs_as_errors=on
define=BOOST_WARNING_AS_ERROR_MUST_SUCCEED :
test_data_truncation_warning_as_errors_must_succeed ]
[ run test_data_truncation.cpp : : warnigs_as_errors=off ]
The question no is how to use this test on compiler that don't warm in this
case. For these compiler
[ compile_fails test_data_truncation.cpp : : warnigs_as_errors=on
define=BOOST_WARNING_AS_ERROR_MUST_FAIL :
test_data_truncation_warning_as_errors_must_fail ]
will fail as the compilation succeeds.
An here is where we can not be independent of the compiler. We need to
determine on the code if the compiler must warms or not:
int main() {
int b = 30000, c = 30000;
#if defined(BOOST_WARNING_AS_ERROR_MUST_FAIL)
short a = b + c; // C4244
#if "compiler don't warms#
#warning "There is no issue with this compiler. warning only to make
the test succeed"
#endif
#elif !defined(BOOST_WARNING_AS_ERROR_MUST_SUCCEED)
short a = static_cast<unsigned short>(b + c);
#else
short a1 = b + c; // C4244
short a2 = static_cast<unsigned short>(b + c);
assert(a1==a2)
#endif
}
Note that we need a specific file by test as we need to check the warning
disappears on the different situations.
I'll continue to look for a better approach. Please let me know what do you
think.
Best,
Vicente
-- View this message in context: http://old.nabble.com/Compiler-Warnings-Tests-tp26545937p26554919.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk