You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// - File 1 -
#include"a.h"
#include"b.h"
B b;
A::A(){
b.Use();
}
// - File 2 -
#include"a.h"
A a;
// - File 3 -
#include"a.h"
#include"b.h"extern A a;
extern B b;
intmain() {
a.Use();
b.Use();
}
For this example, The interpretation for the deferred dynamic initialization may exist something wrong. The comment is:
If, however, a is initialized at some point after the first statement of main, b will be initialized prior to its use in A::A.
In other words, the sentence interprets that when the dynamic initialization is deferred, how to initialize these deferred variable. Although, the non-inline function A::A() is defined at the same TU as the variable b, however the invocation of A::A() is caused by the initialization of a, in other words, the use of A::A() shouldn't be considered as non-initialization odr-use, whose term definition is:
A non-initialization odr-use is an odr-use ([basic.def.odr]) not caused directly or indirectly by the initialization of a non-local static or thread storage duration variable.
Hence, in this situation, the use of A::A() shouldn't cause the initialization of the variable b. The use of b in expression b.Use() is caused indirectly by the initialization of the variable a(as aforementioned), which shouldn't trigger the initialization of the variable b. So, why the comment says that b will be initialized prior to its use in A::A?
The text was updated successfully, but these errors were encountered:
jensmaurer
changed the title
Might be a wrong of the interpretation of the example in [basic.start.dynamic#5]
[basic.start.dynamic] p5 Bad example for deferred initialization
Dec 29, 2020
For this example, The interpretation for the deferred dynamic initialization may exist something wrong. The comment is:
In other words, the sentence interprets that when the dynamic initialization is deferred, how to initialize these deferred variable. Although, the non-inline function
A::A()
is defined at the same TU as the variableb
, however the invocation ofA::A()
is caused by the initialization ofa
, in other words, the use ofA::A()
shouldn't be considered as non-initialization odr-use
, whose term definition is:Hence, in this situation, the use of
A::A()
shouldn't cause the initialization of the variableb
. The use ofb
in expressionb.Use()
is caused indirectly by the initialization of the variablea
(as aforementioned), which shouldn't trigger the initialization of the variableb
. So, why the comment says thatb will be initialized prior to its use in A::A
?Such an issues has been discussed at here.
The text was updated successfully, but these errors were encountered: