clang-format: Align asterisk (*) of pointer declaration with variable name

PointerAlignment: Right is unfortunately not implemented yet. See https://github.com/llvm/llvm-project/blob/master/clang/lib/Format/WhitespaceManager.cpp#L643 void WhitespaceManager::alignConsecutiveDeclarations() { if (!Style.AlignConsecutiveDeclarations) return; // FIXME: Currently we don’t handle properly the PointerAlignment: Right // The * and & are not aligned and are left dangling. Something has to be done // about it, but it raises the question of alignment of code like: … Read more

CMake not generating compile_commands.json

This ended up being an issue with using an old version of CMake. I ended up installing the newest version and it worked as expected. According to Clang docs “Currently CMake (since 2.8.5) supports generation of compilation databases for Unix Makefile builds (Ninja builds in the works) with the option CMAKE_EXPORT_COMPILE_COMMANDS.”

Why clang-tidy suggests to add [[nodiscard]] everywhere?

This option is apparently “modernize-use-nodiscard”, so you can deactivate that if you prefer. It should be noted that the rules this option outlines are not the rules the C++ standard committee themselves use for when to apply [[nodiscard]]. Those rules being: It should be added where: For existing API’s not using the return value always … Read more

How to build the latest clang-tidy?

Up-to-date steps: git clone https://github.com/llvm/llvm-project.git cd llvm-project mkdir build cd build cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=”clang;clang-tools-extra” ../llvm make install clang-tidy Reference, ninja, and other details: my own blog post.

GCC(/Clang): Merging functions with identical instructions (COMDAT folding)

Neither GCC nor Clang is a linker, and ICF needs to be done by the linker, or at least with cooperation with the linker. Edit: They don’t do ICF, so yes, distinct instantiations produce distinct code. The GNU gold linker supports ICF with the –icf option, which needs the GCC option -ffunction-sections to be used. … Read more

The reasoning behind Clang’s implementation of std::function’s move semantics

It is a bug in libc++ that cannot be immediately fixed because it would break ABI. Apparently, it is a conforming implementation, although obviously it is often suboptimal. It’s not clear exactly why the Clang devs made such an implementation choice in the first place (although maybe if you’re really lucky, someone from Clang will … Read more

tech