[PATCH] D101341: Initialize optional members of ELFYAML types.

Vyacheslav Zakharin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 10:14:05 PDT 2021


vzakhari added inline comments.


================
Comment at: llvm/include/llvm/ObjectYAML/ELFYAML.h:661
 struct MipsABIFlags : Section {
-  llvm::yaml::Hex16 Version;
+  llvm::yaml::Hex16 Version{0};
   MIPS_ISA ISALevel;
----------------
MaskRay wrote:
> Let strong typedef Hex16/MIPS_AFL_REG initialize the base value
Sorry, I do not understand this.

Are you suggesting to let Hex16's default constructor to initialize the actual value?  I believe there is no default constructor that would do that.


```
 #define LLVM_YAML_STRONG_TYPEDEF(_base, _type)                                 \
     struct _type {                                                             \
         _type() = default;                                                     \
         _type(const _base v) : value(v) {}                                     \
         _type(const _type &v) = default;                                       \
         _type &operator=(const _type &rhs) = default;                          \
         _type &operator=(const _base &rhs) { value = rhs; return *this; }      \
         operator const _base & () const { return value; }                      \
         bool operator==(const _type &rhs) const { return value == rhs.value; } \
         bool operator==(const _base &rhs) const { return value == rhs; }       \
         bool operator<(const _type &rhs) const { return value < rhs.value; }   \
         _base value;                                                           \
         using BaseType = _base;                                                \
     };
```

Default construction will leave `value` uninitialized for POD `_base` type.  Zero-initializaton will set `value` to 0.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101341/new/

https://reviews.llvm.org/D101341



More information about the llvm-commits mailing list