A lengthy explanation follows, the question is below.
My question specifically relates to the current C ++ standard (but also to the current standard) found here . More specifically, paragraph 6 of section 6 (p. 35) refers to each definition of D shall consist of the same sequence of tokensin relation to member functions and ODR.
I recently encountered the following problem in a project when adding a new data analysis.
I wrote the A.cpp file. I created a small dummy structure for storing data. In this example, I will name it Data.
namespace Example {
struct Data {
};
};
However, in the anther file, B.cpp, a Examplestructure with a name already existed in the namespace Data. The compiler generates Data::~Data();for both classes, which, in turn, calls the destructors of their respective members. The definition in B.cpp contains a vector that, when destroyed, causes explosions when structures are called Datausing the layout defined in A.cpp. Although both structures work correctly, without compile-time errors, it seems that during the linker the linker selects one definition and uses it, ignoring the other definition. (Consequently, explosions at objects Datainside A.cpp were triggered)
No warnings are issued in GCC or under MSVC. When optimization is enabled, the problem does not occur (functions are built-in, there is no confusion of link time).
, , undefined If D is a template and is defined in more than one translation unit.
, undefined ; GCC, MSVC , ( ) ( undefined ).
- , , ( /).