Skip to content

Commit

Permalink
Fix Wdeprecated warnings (common/proto)
Browse files Browse the repository at this point in the history
When using clang, Wdeprecated warns about deprecated implicitly-defined
copy constructors (happens most often due to user-defined destructor,
but in this case is due to the explicit assignment operator):
http://en.cppreference.com/w/cpp/language/copy_constructor#Implicitly-defined_copy_constructor

This patch explicitly defines the desired copy constructor, silencing
the warning in call_python.

We also document the public (but internal) methods in order to reason
about why exposing the copy constructor is correct.
  • Loading branch information
jwnimmer-tri committed Mar 12, 2018
1 parent a290ff2 commit e56368d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions common/proto/call_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,31 @@ template <typename Policy>
class PythonAccessor : public internal::PythonApi<PythonAccessor<Policy>> {
public:
using KeyType = typename Policy::KeyType;

// Given a variable (and key), makes a PythonAccessor.
PythonAccessor(PythonRemoteVariable obj, const KeyType& key)
: obj_(obj), key_(key) {}

// Copying a PythonAccessor aliases the original remote variable (reference
// semantics), it does not create a new remote variable.
PythonAccessor(const PythonAccessor&) = default;

// Implicitly converts to a PythonRemoteVariable.
operator PythonRemoteVariable() const { return value(); }

// Assigning from another PythonAccessor delegates to set_value from that
// `value`'s underlying PythonRemoteVariable.
PythonRemoteVariable operator=(const PythonAccessor& value) {
return set_value(value);
}

// Assigning from another PythonRemoteVariable delegates to set_value from it.
PythonRemoteVariable operator=(const PythonRemoteVariable& value) {
return set_value(value);
}

// Assigning from some literal value creates a new PythonRemoveVariable to
// bind the value.
template <typename T>
PythonRemoteVariable operator=(const T& value) {
return set_value(NewPythonVariable(value));
Expand Down

0 comments on commit e56368d

Please sign in to comment.