Boost logo

Boost :

Subject: Re: [boost] Compiler Warnings Tests
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-11-30 08:25:57

Vicente Botet Escriba
> Stewart, Robert wrote:

> > It might be possible to wrap the code that is supposed to
> > warn with a macro that dictates the expected behavior:
> >
> > BOOST_MUST_WARN(short a1(b + c));
> >
> > Given that mechanism, the example becomes the following:
> >
> > int
> > main()
> > {
> > int b(30000);
> > int c(30000);
> > BOOST_MUST_WARN(short a1(b + c)); // MSVC: C4244
> > short a2(static_cast<unsigned short>(b + c));
> > assert(a1 == a2);
> > #endif
> > }
> >
> > Since initializing a1 is expected to warn on MSVC, the macro
> > will just emit the supplied code when testing for failure
> > with warnings-as-errors. The macro must also emit the code
> > for the warnings-as-warnings equivalence test. For a
> > no-warnings test, the macro must emit nothing.
> >
> > For a compiler that doesn't emit a warning for that statement,
> > BOOST_MUST_WARN must be defined to produce a warning (or to
> > otherwise fail the compilation) in a warnings-as-errors test.
> > Otherwise, it must simply emit the code unchanged.
> I think that BOOST_MUST_WARN don't works as it must add a
> #warning depending on the statement and the compiler.

The preprocessor logic I mentioned would determine whether a particular compiler produces a warning or not and that would dictate how BOOST_MUST_WARN is defined. Since each test file can test a single warning, or group of related warnings, all uses of BOOST_MUST_WARN in that translation unit will behave the same. In different tests, it can behave differently as the test and compiler require.

IOW, after using the preprocessor to determine whether a given compiler produces a warning or not for *a single test*, and setting a manifest constant to indicate that expectation, the boilerplate preprocessor logic will produce a suitable definition of BOOST_MUST_WARN for use in that translation unit. In some cases, it will simply emit the supplied code. In others, it will emit the code and then something that will synthesize an appropriate test outcome.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at