Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-87014

Add a lint to ensure that implicit conversions aren't implicitly implicit

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Service Arch

      One of the worst defaults in C++ is that 1-argument constructors (or constructors that can potentially take 1-argument, eg due to variadics or default arguments) are implictly implicit and you need to remember to explicitly use explicit to avoid that. It is very easy to forget about that, even if you know the rule. In C++20 there is now a way to explictly mark a constructor as implicit: explicit(false). Now that we can detect whether the constructor is intentionally implicit, we should add a lint to prevent implicitly implicit conversions to ensure that all implicit conversions are intentional. The automated "fixit" should just add explicit since that is what you want 99% of the time, but the message should also suggest explicit(false) to silence the warning.

      We could also enforce this for conversion operators explicit(bool) operator Destination(), but I think the value add is much lower there. When adding one of those, you are almost always thinking about conversions, and most of the time you want them to be implicit anyway.

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: