[cfe-dev] More extensive unused variable checks

David Blaikie dblaikie at gmail.com
Tue Apr 16 16:45:02 PDT 2013


On Tue, Apr 16, 2013 at 4:27 PM, Sean Silva <silvas at purdue.edu> wrote:
>
> On Tue, Apr 16, 2013 at 2:32 PM, Daniel B Mosesson <dmosess1 at binghamton.edu>
> wrote:
>>
>> Not really. Const does not enforce no I/O and no modification of
>> pointer targets.
>
>
> For types used in conjunction with the standard library, C++11 actually puts
> pretty stringent requirements on what a const function can do. Basically any
> function marked const that is used in conjunction with the standard library
> must be thread-safe (or else you get undefined behavior).

I've heard about Herb Sutter talking about this, but I didn't/don't
think it's actually enshrined in the standard, is it? I don't believe
there's any requirement that, say, the elements of a std::vector
implement those semantics even if the vector is used from multiple
threads (with vector providing the "usual thread safety guarantees" of
multiple threads using const operations or one thread exclusively
using non-const operations) - because the const operations of vector
don't actually call anything on the contained elements, for example.

> The const member
> function in your example can easily be seen to race in a multithreaded
> context.
>
> See this for more info:
> http://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank
>
> So const may be strong enough for your analyses under the new rules.
>
> -- Sean Silva



More information about the cfe-dev mailing list