[PATCH] D147357: [clang-tidy] Add bugprone-optional-value-conversion check

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 10 15:34:37 PDT 2023


PiotrZSL added a comment.

As for `takeOptionalValue(std::move(*param));`, it could be added as an configuration option for PassthroughFunctions or UtilityFunctions. I can thing about that, that should be easy to implement.



================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/optional-value-conversion.rst:34
+Value extraction using ``operator *`` is matched by default.
+Check does not provide auto-fixes.
+
----------------
njames93 wrote:
> Any reason for this limitation, given in most cases the fix is to just remove the `*` or `.value()` call
Sometimes problem is not with optional but with called function that take optional when it could take value.
At least for such issues I run, still probably could be safe to introduce such auto-fix to just remove */.value().
But then question would be if it should be bugprone or readability check.
For me like 10% of these issues show some possible bug around that code.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp:16
+  };
+}
+
----------------
njames93 wrote:
> It'd be good to have tests demonstating `boost::optional` and `absl::optional` as well as the (non standard) get accessor
I added them to config just to add them, as they should work, I could add some tests for them, but behavior should be same...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147357



More information about the cfe-commits mailing list