diff options
author | zenith432 <zenith432@users.sourceforge.net> | 2017-12-06 16:46:37 +0000 |
---|---|---|
committer | Liming Gao <liming.gao@intel.com> | 2018-01-02 20:37:38 +0800 |
commit | 5397bd425eba0cd00c5f76c8d35f328ca625db0e (patch) | |
tree | 7db49b3dc146e74982a4f0e63351a02b2244a9ba /BaseTools/Source/Python/GenFds | |
parent | 4e97974c1e52c2fcd2640398b17266dff001b699 (diff) | |
download | edk2-5397bd425eba0cd00c5f76c8d35f328ca625db0e.tar.gz edk2-5397bd425eba0cd00c5f76c8d35f328ca625db0e.tar.bz2 edk2-5397bd425eba0cd00c5f76c8d35f328ca625db0e.zip |
BaseTools: resolve initialization order errors in VfrFormPkg.h
clang generates many warnings
warning: field 'XXX' is uninitialized when used here [-Wuninitialized]
for VfrFormPkg.h.
VfrFormPkg.h defines many classes derived from CIfrObj (along with other
base classes.)
Each of these derived classes defines a non-static member field that serves
as a duplicate pointer to an original pointer defined in the CIfrObj base
class, but cast to a different pointer type.
The derived class constructor passes the duplicate pointer to base class
constructors:
1) Once passes the address of the duplicate pointer to the CIfrObj
constructor to have it initialized.
2) Then passes the duplicate pointer to one or more subsequent base class
constructors to be used.
Both 1) and 2) constitute undefined behavior in C++. C++ prescribes that
base classes are initialized before non-static members when initializing a
derived class. So when base class constructors are executing, it is not
permitted to assume any non-static members of the derived class exist (even
to the stage of having their storage allocated.)
clang does not issue warnings for 1), but issues warnings -Wuninitialized
for 2).
This coding methodology is resolved as follows:
a) The CIfrObj object accessor method for retrieving the original pointer
is revised to a template member function that returns the original
pointer cast to a desired target type.
b) The call to CIfrObj constructor is no longer used to initialize the
duplicate pointer in the derived class.
c) Any subsequent calls to a base class constructor that need to use the
pointer, retrieve it from the CIfrObj base class using the template
accessor method.
d) If the derived class makes no further use of the pointer, then the
duplicate pointer defined in it is eliminated.
e) If the derived class needs the duplicate pointer for other use, the
duplicate pointer remains in the derived class and is initialized in
proper order from the original pointer in CIfrObj.
f) Existing source code that previously used the CIfrObj pointer accessor
method is revised to use the template method.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zenith432 <zenith432@users.sourceforge.net>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/GenFds')
0 files changed, 0 insertions, 0 deletions