-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[clang-tidy] Add support for bsl::optional #101450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7e7681
[clang-tidy] Add support for bsl::optional
ccotter 5ed4ef3
Update docs
ccotter bd2aa7d
Review feedback
ccotter be9b79e
Merge remote-tracking branch 'upstream/main' into bsl
ccotter 884a44a
Merge branch 'main' into bsl
ccotter a064dd9
Merge branch 'main' of https://github.com/llvm/llvm-project into bsl
ccotter 28e9ec4
Update clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unc…
ccotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ng-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_ | ||
#define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_ | ||
|
||
#include "bsl_optional.h" | ||
|
||
/// Mock of `bdbl::NullableValue`. | ||
namespace BloombergLP::bdlb { | ||
|
||
template <typename T> | ||
class NullableValue : public bsl::optional<T> { | ||
public: | ||
constexpr NullableValue() noexcept; | ||
|
||
constexpr NullableValue(bsl::nullopt_t) noexcept; | ||
|
||
NullableValue(const NullableValue &) = default; | ||
|
||
NullableValue(NullableValue &&) = default; | ||
|
||
const T &value() const &; | ||
T &value() &; | ||
|
||
// 'operator bool' is inherited from bsl::optional | ||
|
||
constexpr bool isNull() const noexcept; | ||
|
||
template <typename U> | ||
constexpr T valueOr(U &&v) const &; | ||
|
||
// 'reset' is inherited from bsl::optional | ||
|
||
template <typename U> NullableValue &operator=(const U &u); | ||
}; | ||
|
||
|
||
} // namespace BloombergLP::bdlb | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_ |
75 changes: 75 additions & 0 deletions
75
...st/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_ | ||
#define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_ | ||
|
||
/// Mock of `bsl::optional`. | ||
namespace bsl { | ||
|
||
// clang-format off | ||
template <typename T> struct remove_reference { using type = T; }; | ||
template <typename T> struct remove_reference<T&> { using type = T; }; | ||
template <typename T> struct remove_reference<T&&> { using type = T; }; | ||
// clang-format on | ||
|
||
template <typename T> | ||
using remove_reference_t = typename remove_reference<T>::type; | ||
|
||
template <typename T> | ||
constexpr T &&forward(remove_reference_t<T> &t) noexcept; | ||
|
||
template <typename T> | ||
constexpr T &&forward(remove_reference_t<T> &&t) noexcept; | ||
|
||
template <typename T> | ||
constexpr remove_reference_t<T> &&move(T &&x); | ||
|
||
struct nullopt_t { | ||
constexpr explicit nullopt_t() {} | ||
}; | ||
|
||
constexpr nullopt_t nullopt; | ||
|
||
template <typename T> | ||
class optional { | ||
public: | ||
constexpr optional() noexcept; | ||
|
||
constexpr optional(nullopt_t) noexcept; | ||
|
||
optional(const optional &) = default; | ||
|
||
optional(optional &&) = default; | ||
|
||
const T &operator*() const &; | ||
T &operator*() &; | ||
const T &&operator*() const &&; | ||
T &&operator*() &&; | ||
|
||
const T *operator->() const; | ||
T *operator->(); | ||
|
||
const T &value() const &; | ||
T &value() &; | ||
const T &&value() const &&; | ||
T &&value() &&; | ||
|
||
constexpr explicit operator bool() const noexcept; | ||
constexpr bool has_value() const noexcept; | ||
|
||
template <typename U> | ||
constexpr T value_or(U &&v) const &; | ||
template <typename U> | ||
T value_or(U &&v) &&; | ||
|
||
template <typename... Args> | ||
T &emplace(Args &&...args); | ||
|
||
void reset() noexcept; | ||
|
||
void swap(optional &rhs) noexcept; | ||
|
||
template <typename U> optional &operator=(const U &u); | ||
}; | ||
|
||
} // namespace bsl | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.