Suppose I have:
struct Foo {
static void bar();
};
Foo foo() { return Foo(); }
In the expression foo().bar() is the call to foo guaranteed to happen BEFORE the call to bar()? Where is this stated in the standard?
The doubt is because the value of the result of the call is not used, and the type is known at compile time...
[expr.ref] p1 states:
This means that for
E1.E2,E1takes place beforeE1.E2, but there is no sequencing ofE1andE2(1). You have a function call of the patternfoo().bar(). The function call tobaris sequenced afterfoo().baras a whole.Therefore yes, the call to
foo()happens before the call tobar().Interestingly, the wording does not use the term "sequenced", which is unusual and likely an editorial issue.
(1)
E2is an id-expression (e.g.foo) which is either a qualified-id or unqualified-id, and such an expression in itself performs no value computation and has no side effects. There is nothing to be sequenced anyway.