Page MenuHomePhabricator

[lld] Add double-braces for std::array to suppress warnings. NFC.
AbandonedPublic

Authored by Higuoxing on Apr 13 2019, 12:26 AM.

Details

Reviewers
ruiu
espindola
Summary

This patch helps suppress warnings when building lld.
According to https://en.cppreference.com/w/cpp/container/array, double-braces required in C++11 prior to the CWG 1270 revision
(not needed in C++11 after the revision and in C++14 and beyond)

/Users/me/Workspace/llvm/llvm-project/lld/ELF/Arch/MSP430.cpp:44:16: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  TrapInstr = {0x43, 0x43, 0x43, 0x43};
               ^~~~~~~~~~~~~~~~~~~~~~
               {                     }
1 warning generated.
[4/9] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/Arch/ARM.cpp.o
/Users/me/Workspace/llvm/llvm-project/lld/ELF/Arch/ARM.cpp:63:16: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  TrapInstr = {0xd4, 0xd4, 0xd4, 0xd4};
               ^~~~~~~~~~~~~~~~~~~~~~
               {                     }
1 warning generated.
[5/9] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/Arch/X86.cpp.o
/Users/me/Workspace/llvm/llvm-project/lld/ELF/Arch/X86.cpp:62:16: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  TrapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3
               ^~~~~~~~~~~~~~~~~~~~~~
               {                     }
1 warning generated.
[6/9] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/Arch/X86_64.cpp.o
/Users/me/Workspace/llvm/llvm-project/lld/ELF/Arch/X86_64.cpp:65:16: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  TrapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3
               ^~~~~~~~~~~~~~~~~~~~~~
               {                     }
1 warning generated.
[7/9] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/OutputSections.cpp.o
/Users/me/Workspace/llvm/llvm-project/lld/ELF/OutputSections.cpp:412:11: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  return {0, 0, 0, 0};
          ^~~~~~~~~~
          {         }
1 warning generated.

Event Timeline

Higuoxing created this revision.Apr 13 2019, 12:26 AM

rC314838 (included in clang 6) suppressed -Wmissing-braces (enabled by -Wmost and -Wall) warning for the idiomatic brace elision.

http://lists.llvm.org/pipermail/llvm-dev/2019-April/131486.html llvm will migrate to C++14 soon... (though clang < 6 will continue warning the case; I'm not sure if we want to make code less idiomatic just to suppress warnings for old clang; gcc -Wall doesn't enable -Wmissing-braces)

rC314838 (included in clang 6) suppressed -Wmissing-braces (enabled by -Wmost and -Wall) warning for the idiomatic brace elision.

http://lists.llvm.org/pipermail/llvm-dev/2019-April/131486.html llvm will migrate to C++14 soon... (though clang < 6 will continue warning the case; I'm not sure if we want to make code less idiomatic just to suppress warnings for old clang; gcc -Wall doesn't enable -Wmissing-braces)

Thanks a lot for pointing this out. Actually, I'd prefer not using double-braces. Just a few days ago, I saw a commit that added double-braces to suppress this warning in another project, so I put it here for discussion.

ruiu added a comment.Apr 14 2019, 10:35 PM

Yeah, if recent versions of clang and gcc are happy with the code, I wouldn't add the extra braces as Fangrui suggested. Thank you for your effort to fix warnings, though. It's important to keep our code warning-free.

Higuoxing abandoned this revision.Apr 14 2019, 10:41 PM