from Hacker News

Squashing my dumb bugs and why I log build IDs

by wglb on 8/7/25, 3:20 PM with 14 comments

  • by tylerhou on 8/11/25, 2:30 AM

    If you are willing to return std::optional, clang-tidy has a (static) control flow sensitive check that enforces you check to see the value is valid before unwrapping. https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unch...

    This would prevent the last bug (!ua()) as the control flow sensitive analysis can reason about both branches: that it is invalid to deref ua within the block. The dynamic check misses the bug because the branch is never taken for the given inputs.

    I am fairly confident that the clang-tidy pass is simpler and more precise in most cases than the hand-rolled implementation. (That said the static check may not be able to reason about mutation well.)

    If you need to pass an error in the failure case, you can use std::expected (available in C++23). clang-tidy has an open bug about supporting a similar check for std::expected: https://github.com/llvm/llvm-project/issues/135045

  • by mananaysiempre on 8/11/25, 1:51 AM

    Funny if only marginally related fact: even though neither the C++11 syntax

      if (int x = foo(); x) { ... }
    
    nor the C++98 syntax

      if (int x = foo()) { ... }
    
    is supported in C99, it still introduces the rule that the entire if statement is a scope (which it wasn’t in C89). So as a party trick, here’s a way to check for C99 without using the preprocessor:

      int c99() {
          enum { C99 = 1 };
          {
              if (sizeof(enum { C99 = 0 })) { }
              return C99;
          }
      }
    
    I make no promises about the behaviour of this code on insufficiently anal compilers like TCC.
  • by rerdavies on 8/11/25, 6:08 AM

    Isn't that what git tags are for? Just create a tag with something human-readable like, I dunno, a version number would be good. And that way ANYONE can see the state of your sources for a given build.

    If you use github release workflow, you don't even have a choice about it. You cannot create a release without creating a matching tag.

  • by themafia on 8/11/25, 4:45 AM

    Keep in mind that with U+258x characters you get a unique paired set by just inverting the foreground and background. This does work with some, but not all, of the U+259x characters as well.

    You may very well be able to ditch colors using this technique with additional characters. Many characters are distinct with their inverted counterpart.