aboutsummaryrefslogtreecommitdiff
path: root/absl/synchronization/mutex_test.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2023-12-18 12:37:32 -0800
committerCopybara-Service <copybara-worker@google.com>2023-12-18 12:38:18 -0800
commit8900d7c496afb0fb0e0a737d001a46828bc446dd (patch)
treec89237017baee1e83f54a7f09ff7c4ddf9bbe664 /absl/synchronization/mutex_test.cc
parentd22aa4df3f530872d4e11e3906c9c6e002deefca (diff)
downloadabseil-8900d7c496afb0fb0e0a737d001a46828bc446dd.tar.gz
abseil-8900d7c496afb0fb0e0a737d001a46828bc446dd.tar.bz2
abseil-8900d7c496afb0fb0e0a737d001a46828bc446dd.zip
Mutex: Fix Condition pointer-to-member cast to respect const qualifier
Previously, `absl::Condition` incorrectly used the same (non-`const`) pointer-to-method type when wrapping both `const` and non-`const` methods. Unfortunately, this is undefined behavior according to `[expr.reinterpret.cast]` in the C++ standard: > The effect of calling a function through a pointer to a function type that is > not the same as the type used in the definition of the function is undefined. This fixes the UB. PiperOrigin-RevId: 591981682 Change-Id: Iaca955346699417232383d3a1800ea9b82ea5761
Diffstat (limited to 'absl/synchronization/mutex_test.cc')
-rw-r--r--absl/synchronization/mutex_test.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/absl/synchronization/mutex_test.cc b/absl/synchronization/mutex_test.cc
index 35b43334..a8d75827 100644
--- a/absl/synchronization/mutex_test.cc
+++ b/absl/synchronization/mutex_test.cc
@@ -977,6 +977,15 @@ TEST(Mutex, FunctionPointerConditionWithDerivedToBaseConversion) {
const Derived *>::value));
}
+struct Constable {
+ bool WotsAllThisThen() const { return true; }
+};
+
+TEST(Mutex, FunctionPointerConditionWithConstMethod) {
+ const Constable chapman;
+ EXPECT_TRUE(absl::Condition(&chapman, &Constable::WotsAllThisThen).Eval());
+}
+
struct True {
template <class... Args>
bool operator()(Args...) const {