[LockConsistency] Adding conditional ownership to the rest of the formal parameters of constructors.
Reviewed By: sblackshear Differential Revision: D6519671 fbshipit-source-id: 7508fe0master
parent
22ec29fabc
commit
d8a004f0cc
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace constructor_formals {
|
||||
|
||||
struct Y {
|
||||
Y() : rawStatus_(-3) {}
|
||||
Y(const Y& p) = default;
|
||||
Y& operator=(const Y& p) = default;
|
||||
Y(Y&& p) noexcept : rawStatus_(p.rawStatus_) { p.rawStatus_ = -3; }
|
||||
|
||||
int rawStatus_;
|
||||
};
|
||||
|
||||
struct S {
|
||||
Y w() { return returnCode; }
|
||||
|
||||
Y returnCode;
|
||||
};
|
||||
|
||||
struct SU {
|
||||
void p() {
|
||||
S s;
|
||||
auto result = s.w();
|
||||
}
|
||||
};
|
||||
|
||||
class Basic {
|
||||
public:
|
||||
Basic() {}
|
||||
|
||||
int test_locked() {
|
||||
SU su;
|
||||
mutex_.lock();
|
||||
su.p();
|
||||
}
|
||||
|
||||
int test_not_locked() {
|
||||
SU su;
|
||||
su.p(); // FP fixed after adding ownership to formal parameters of
|
||||
// constructors
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
} // namespace constructor_formals
|
Loading…
Reference in new issue