regression in clang-tidy `bugprone-unchecked-optional-access` with newer libc++
There are some regressions in the clang tidy bugprone-unchecked-optional-access with newer libc++.
I believe after:
- https://github.com/llvm/llvm-project/pull/183230 , the checker will start having false positives (doesn't properly match the
has_value()calls for checks) - https://github.com/llvm/llvm-project/pull/185252, the checker will start having false negatives (doesn't properly match the
value,operator*, andoperator->)
Initial thought is we need to adjust something around here (getPublicReceiverType).
@llvm/issue-subscribers-clang-tidy
Author: Jan Voung (jvoung)
I believe after:
- https://github.com/llvm/llvm-project/pull/183230 , the checker will start having false positives (doesn't properly match the
has_value()calls for checks) - https://github.com/llvm/llvm-project/pull/185252, the checker will start having false negatives (doesn't properly match the
value,operator*, andoperator->)
Initial thought is we need to adjust something around here (getPublicReceiverType).
@smallp-o-p are the changes urgent? If not, would you mind reverting while we work on the fix?
They're NFC, so it should be okay to revert.
Gonna ping @philnik77 @ldionne to help me revert, since I don't have commit access.
Thank you @smallp-o-p !
One question is, is it intentional that the inheritance of __optional_iterator_base is public for optional? It seems like it exposes some of the internals? Making the inheritance private also helps fix part of this.
Thank you @smallp-o-p !
One question is, is it intentional that the inheritance of
__optional_iterator_baseispublicforoptional? It seems like it exposes some of the internals? Making the inheritance private also helps fix part of this.
It's intentional, we can't just use
using __base::begin
using __base::end
in optional itself because it begin() and end() may not exist for certain types such as references to arrays and references to function types. This would cause a compile error when they're allowed types for optional
It's possible I should have put the using __base ... statement in the iterator base into a private block, but I'm unsure about that just yet.
Do we really need to revert changes on libc++ side if the issue is on clang-tidy for using internal details? If libstdc++ refactored optional, we wouldn't ask them to revert changes, right?
By commit date it seems that these changes didn't land in 22 release so we have plenty of time to fix it till 23 release branches on Jul 14th, 2026
Fair enough about reverts -- ok, I have a possible fix to make things less dependent on the inheritance structure. Testing now!
Forgot to update the registerMatchers -- one more piece to fix https://github.com/llvm/llvm-project/pull/191681