-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter (unless configured in github; will be published with the issue): Jakub Jelinek
Reference (section label): [basic.indet]
Link to reflector thread (if any):
Issue description:
[stmt.dcl]/2 says it is valid to jump (say through switch or goto) across declaration of a variable with vacuous initialization.
With the P2795R5 introduction of erroneous behavior I don't see how it is implementable though, the prior art the paper mentiones (clang and gcc -ftrivial-auto-var-init={zero,pattern}) but those really don't ensure initialization in those cases (gcc even has -Wtrivial-auto-var-init warning to warn about cases like that). In my understanding the erroneous behavior requirement can be implemented by adding special magic initialization of the automatic variables, parameter slots if some non-trivial copy ctors (or other kinds of ctors) are invoked on those or temporary objects. So basically the standard asks for any variable declaration not to be vacuous anymore (in the implementation). But jumps across that initialization will still see uninitialized memory and so accesses to the vars with vacuous initialization across whose initialization code jumped will be still uninitialized and so still can't guarantee e.g. equality of multiple reads from that location resulting in the same value.
Consider:
struct S { S () = default; int a, b, c; };
void bar (S &, int &);
void
foo (int x)
{
switch (x)
{
case 1:
S a;
a.a = 1; a.b = 2;
int b;
b = 3;
bar (a, b);
/* FALLTHRU */
case 2:
a.a = 4; a.b = 5;
b = 6;
bar (a, b);
/* FALLTHRU */
case 3:
bar (a, b);
break;
case 4:
goto end;
default:
break;
}
S c;
int d;
c.a = 7; c.b = 8;
d = 9;
end:
bar (c, d);
}
And another thing, I see [[indeterminate]] attribute being allowed only on parameter declarations of function declarations. That means one can opt-out for specific arguments to direct calls to the particular function. But shouldn't one be able to specify it also on for parameter declarations on function types as well, so that even virtual method calls or calls through function pointers etc. can opt-out of it?
Or does that open an unwanted pandorra box of taking the attributes into account for function type equality, having to mangle it etc.?
Suggested resolution: