mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Add explicit to conversions (#9336)
Summary: Another code-mod for clang-tidy: Conversion operators should be marked explicit so that they don't cause unwanted implicit conversions. This is especially important for `operator bool()`, see https://stackoverflow.com/questions/39995573/when-can-i-use-explicit-operator-bool-without-a-cast ezyang apaszke Pull Request resolved: https://github.com/pytorch/pytorch/pull/9336 Reviewed By: apaszke Differential Revision: D8807065 Pulled By: goldsborough fbshipit-source-id: 0e9f4ebd0048a2a510c0d05fa410695d7e977eb1
This commit is contained in:
parent
c2dd90c40e
commit
18a975210d
56
.clang-tidy
56
.clang-tidy
|
|
@ -3,36 +3,38 @@
|
||||||
Checks: '
|
Checks: '
|
||||||
*
|
*
|
||||||
,modernize-*
|
,modernize-*
|
||||||
,clang-analyzer-*
|
|
||||||
,-clang-diagnostic-*
|
|
||||||
,-hicpp-no-array-decay
|
|
||||||
,-fuchsia-*
|
|
||||||
,-google-readability-namespace-comments
|
|
||||||
,-llvm-namespace-comment
|
|
||||||
,-google-readability-todo
|
|
||||||
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
|
|
||||||
,-cert-err60-cpp
|
|
||||||
,-llvm-header-guard
|
|
||||||
,-cppcoreguidelines-special-member-functions
|
|
||||||
,-misc-unused-parameters
|
|
||||||
,-hicpp-braces-around-statements
|
|
||||||
,-hicpp-special-member-functions
|
|
||||||
,-readability-braces-around-statements
|
|
||||||
,-modernize-use-default-member-init
|
|
||||||
,-google-runtime-references
|
|
||||||
,-cppcoreguidelines-pro-type-vararg
|
|
||||||
,-google-readability-braces-around-statements
|
|
||||||
,-google-build-using-namespace
|
|
||||||
,-hicpp-vararg
|
|
||||||
,-hicpp-explicit-conversions
|
|
||||||
,-performance-unnecessary-value-param
|
|
||||||
,-google-runtime-references
|
|
||||||
,-cppcoreguidelines-pro-type-static-cast-downcast
|
|
||||||
,-cppcoreguidelines-pro-bounds-constant-array-index
|
|
||||||
,-cert-err58-cpp
|
,-cert-err58-cpp
|
||||||
,-modernize-make-unique
|
,-cert-err60-cpp
|
||||||
|
,-clang-diagnostic-*
|
||||||
,-cppcoreguidelines-owning-memory
|
,-cppcoreguidelines-owning-memory
|
||||||
|
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
|
||||||
|
,-cppcoreguidelines-pro-bounds-constant-array-index
|
||||||
|
,-cppcoreguidelines-pro-type-static-cast-downcast
|
||||||
|
,-cppcoreguidelines-pro-type-vararg
|
||||||
|
,-cppcoreguidelines-special-member-functions
|
||||||
|
,-fuchsia-*
|
||||||
|
,-google-build-using-namespace
|
||||||
|
,-google-explicit-constructor
|
||||||
|
,-google-readability-braces-around-statements
|
||||||
|
,-google-readability-namespace-comments
|
||||||
|
,-google-readability-todo
|
||||||
|
,-google-runtime-references
|
||||||
|
,-google-runtime-references
|
||||||
|
,-hicpp-braces-around-statements
|
||||||
|
,-hicpp-explicit-conversions
|
||||||
|
,-hicpp-no-array-decay
|
||||||
|
,-hicpp-special-member-functions
|
||||||
|
,-hicpp-vararg
|
||||||
|
,-llvm-header-guard
|
||||||
|
,-llvm-namespace-comment
|
||||||
|
,-misc-unused-parameters
|
||||||
|
,-modernize-make-unique
|
||||||
|
,-modernize-use-default-member-init
|
||||||
|
,-performance-unnecessary-value-param
|
||||||
|
,-readability-braces-around-statements
|
||||||
|
,-readability-else-after-return
|
||||||
,-readability-named-parameter
|
,-readability-named-parameter
|
||||||
|
,clang-analyzer-*
|
||||||
'
|
'
|
||||||
WarningsAsErrors: ''
|
WarningsAsErrors: ''
|
||||||
HeaderFilterRegex: 'torch/csrc/'
|
HeaderFilterRegex: 'torch/csrc/'
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ using value_list = std::vector<Value*>;
|
||||||
// Terminology: vjp = vector-jacobian product
|
// Terminology: vjp = vector-jacobian product
|
||||||
|
|
||||||
struct Gradient {
|
struct Gradient {
|
||||||
operator bool() const {
|
explicit operator bool() const {
|
||||||
return df != nullptr;
|
return df != nullptr;
|
||||||
}
|
}
|
||||||
std::shared_ptr<Graph> f;
|
std::shared_ptr<Graph> f;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ struct GraphExecutor {
|
||||||
// note: if not specified, symbolically_differentiable is computed from the graph.
|
// note: if not specified, symbolically_differentiable is computed from the graph.
|
||||||
GraphExecutor(std::shared_ptr<Graph> graph, bool optimize, bool symbolically_differentiable);
|
GraphExecutor(std::shared_ptr<Graph> graph, bool optimize, bool symbolically_differentiable);
|
||||||
variable_tensor_list run(variable_tensor_list && inputs);
|
variable_tensor_list run(variable_tensor_list && inputs);
|
||||||
operator bool() const {
|
explicit operator bool() const {
|
||||||
return pImpl != nullptr;
|
return pImpl != nullptr;
|
||||||
}
|
}
|
||||||
std::shared_ptr<Graph> graph() const;
|
std::shared_ptr<Graph> graph() const;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ struct Code {
|
||||||
// Returns pointers to GraphExecutors created to run GraphExecutor nodes in the given graph.
|
// Returns pointers to GraphExecutors created to run GraphExecutor nodes in the given graph.
|
||||||
const std::vector<GraphExecutor*>& executors();
|
const std::vector<GraphExecutor*>& executors();
|
||||||
|
|
||||||
operator bool() const {
|
explicit operator bool() const {
|
||||||
return pImpl != nullptr;
|
return pImpl != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ struct TreeToken {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool() {
|
explicit operator bool() {
|
||||||
return is_root;
|
return is_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public:
|
||||||
THPPointer& operator =(T *new_ptr) { free(); ptr = new_ptr; return *this; }
|
THPPointer& operator =(T *new_ptr) { free(); ptr = new_ptr; return *this; }
|
||||||
THPPointer& operator =(THPPointer &&p) { free(); ptr = p.ptr; p.ptr = nullptr; return *this; }
|
THPPointer& operator =(THPPointer &&p) { free(); ptr = p.ptr; p.ptr = nullptr; return *this; }
|
||||||
T * operator ->() { return ptr; }
|
T * operator ->() { return ptr; }
|
||||||
operator bool() const { return ptr != nullptr; }
|
explicit operator bool() const { return ptr != nullptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void free();
|
void free();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user