[cpp-threads] Static member functions, member access syntax and sequenced-before

Peter Dimov pdimov at mmltd.net
Wed Nov 23 18:38:41 GMT 2011


N.M. Maclaren wrote:
> This arose today in the context of MPI.  9.4 [class.static] paragraph 2
> says:
>
>     A static member s of class X may be referred to using the
>     qualified-id expression X::s; it is not necessary to use the class
>     member access syntax to refer to a static member. A static member
>     may be referred to using the class member access syntax, in which
>     case the object-expression is evaluated.
>
> The relevant MPI construction is, in summary:
>
>     class Request {
>     static void Waitall (...);
>     }
>
>     Request requests[100];
>     requests[0].Waitall(100,requests,...);
>
> Now, is the evaluation of requests[0] sequenced-before the call to
> Waitall or not?  The latter assuredly doesn't need the value.  This
> isn't particularly serious for MPI, but obviously matters in general.
>
> In particular, if it is not specified to be sequenced-before, then
> a defined program can become undefined purely because a class has
> 'transparently' changed a non-static member function that does not
> use 'this' to a static one.
>
> If it is so specified, I can't find it, because 1.7 paragraph 15 and
> 1.10 paragraph 9 are in terms of value computation, and there IS no
> value computation involved in the call to Waitall!

1.9 [intro.execution] p15 in my N3290 says that "When calling a function 
(whether or not the function is inline), every value computation and side 
effect associated with any argument expression, or with the postfix 
expression designating the called function, is sequenced before execution of 
every expression or statement in the body of the called function."

The postfix expression designating the called function is 
requests[0].Waitall. The value computation of requests[0] is sequenced 
before the function call. requests[0] is evaluated even when Waitall is 
static. (5.2.5 [expr.ref] p1 and footnote 64).




More information about the cpp-threads mailing list