Is evaluation of the initializer sequenced before the initialization?

40 views
Skip to first unread message

xskxzr

unread,
Apr 19, 2018, 10:29:25 AM4/19/18
to ISO C++ Standard - Discussion
Hi all,

Is evaluation of the initializer sequenced before the initialization?

I think so because

1. otherwise the example in [basic.scope.pdecl]/1 would be undefined:
unsigned char x = 12;
{ unsigned char x = x; }

2. The right operand of assignment operator is sequenced before the assignment, and it should be analogous for initialization.

However, I cannot find any rule saying about this. Am I missing something, or is it a defect?

Thanks
xskxzr

Bo Persson

unread,
Apr 19, 2018, 10:58:39 AM4/19/18
to std-dis...@isocpp.org
On 2018-04-19 16:29, xskxzr wrote:
> Hi all,
>
> Is evaluation of the initializer sequenced before the initialization?
>
> I think so because
>
> 1. otherwise the example in [basic.scope.pdecl]/1
> <http://www.eel.is/c++draft/basic.scope.pdecl#1> would be undefined:
> |
> unsignedcharx =12;
> {unsignedcharx =x;}
> |
>

And it is. The very next sentence is

"Here the second x is initialized with its own (indeterminate) value".




Bo Persson


richar...@gmail.com

unread,
Apr 19, 2018, 12:17:49 PM4/19/18
to ISO C++ Standard - Discussion, b...@gmb.dk
Clearly the value computation of the initializer is sequenced before the initialization (because there's a dependency on the value).

But on Stack Overflow we found potential ambiguity concerning whether side effects of the initializer expression are sequenced before the initialization.

xskxzr

unread,
Apr 19, 2018, 11:09:44 PM4/19/18
to ISO C++ Standard - Discussion, b...@gmb.dk
No. 

[dcl.init]/12:

If an indeterminate value is produced by an evaluation, the behavior is undefined except in the following cases:
...
-- If an indeterminate value of unsigned narrow character type is produced by the evaluation of the initialization expression when initializing an object of unsigned narrow character type, that object is initialized to an indeterminate value.
Reply all
Reply to author
Forward
0 new messages