[PATCH] D152083: [clang] Warning for uninitialized elements in fixed-size arrays

Louis Burda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 8 10:32:44 PDT 2023


Sinitax added a comment.

> Why do you make this a new warning group instead of just adding it to -Wuninitialized?

I think a separate group is best, since the warning emits false positives: an intentional empty-initialization (such as `char buf[BUF_SIZ] = { 0 }`) is indistinguishable from unintentionally incomplete initialization (such as `int pair[2] = { ENUM_A /*, ENUM_B */ }`).

For this reason users would want to selectively enable it..

  #pragma clang diagnostic push
  #pragma clang diagnostic warning "-Wincomplete-initializer-list"
  
  const char *errmsg[ERR_COUNT] = {
      [ERR_A] = "error a",
  };
  
  #pragma clang diagnostic pop

.. but I'm not really satisfied with this solution. Feedback on how to differentiate between the aforementioned cases, if possible, is appreciated.


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

https://reviews.llvm.org/D152083



More information about the cfe-commits mailing list