From f8d29690b9e8082dd5bad2c2a440ef2ae724a307 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 8 Nov 2025 03:52:57 +0300 Subject: [PATCH] Fix potential ambiguity of the comparison operator for BranchParameter. C++20 introduces support for comparison operator rewriting. In particular, the compiler is now able to synthesize comparison operators with swapped arguments, so e.g. for operator==(A, B) it would synthesize operator==(B, A). This poses a problem for BranchParameter::operator==, which is declared non-const and accepts a const BranchParameter& argument. The above rewriting would synthesize a different operator== that is marked as const but accepts a non-const BranchParameter& argument. Invoking comparison between two non-const BranchParameter objects would therefore be ambiguous as the original and the synthesized overloads would both equally match. Gcc 14 gratiously accepts such code, albeit with a warning, but other compilers may reject it. Fix this by marking the operator== as const. --- resip/stack/BranchParameter.cxx | 2 +- resip/stack/BranchParameter.hxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resip/stack/BranchParameter.cxx b/resip/stack/BranchParameter.cxx index 169cb4186..213bd6c05 100644 --- a/resip/stack/BranchParameter.cxx +++ b/resip/stack/BranchParameter.cxx @@ -159,7 +159,7 @@ BranchParameter::operator=(const BranchParameter& other) } bool -BranchParameter::operator==(const BranchParameter& other) +BranchParameter::operator==(const BranchParameter& other) const { if (mIsMyBranch != other.mIsMyBranch || mHasMagicCookie != other.mHasMagicCookie || diff --git a/resip/stack/BranchParameter.hxx b/resip/stack/BranchParameter.hxx index f940fac0a..3b31911a6 100644 --- a/resip/stack/BranchParameter.hxx +++ b/resip/stack/BranchParameter.hxx @@ -67,7 +67,7 @@ class BranchParameter : public Parameter BranchParameter(const BranchParameter& other); BranchParameter& operator=(const BranchParameter& other); - bool operator==(const BranchParameter& other); + bool operator==(const BranchParameter& other) const; Type& value() {return *this;}