Repository navigation
chore: remove always-defined FIREBASE_USE_MOVE_OPERATORS and FIREBASE_USE_STD_FUNCTION macros - #1995
AustinBenoit wants to merge 2 commits into
Conversation
…_USE_STD_FUNCTION macros - Remove FIREBASE_USE_MOVE_OPERATORS and FIREBASE_USE_STD_FUNCTION definitions and follow-up TODO from app/src/include/firebase/internal/common.h (following #1958). - Unwrap all 90 #if/#ifdef guards across 72 files in app, auth, database, functions, and storage, keeping #ifndef SWIG on SWIG-parsed public headers so Unity SWIG output is unchanged. - Fix include ordering for unwrapped <functional>/<utility> headers and add missing #include <utility> in intrusive_list.h, intrusive_list_test.cc, jobject_reference.cc, and callable_result.h. - Fix newly Doxygen-exposed move-assignment comments in future.h and mutable_data.h. - Fix newly activated intrusive_list/intrusive_list_node move-assignment safety (self-move guard, clear() before overwrite, direct move-ctor member initialization) with regression tests.
❌ Integration test FAILEDRequested by @AustinBenoit on commit 10da95e
Add flaky tests to go/fpl-cpp-flake-tracker |
There was a problem hiding this comment.
Code Review
This pull request removes the obsolete FIREBASE_USE_MOVE_OPERATORS and FIREBASE_USE_STD_FUNCTION preprocessor guards across the codebase, enabling move semantics and std::function support unconditionally. It also refactors the move constructor and move assignment operator of intrusive_list to handle self-assignment and cleanups. Feedback on these changes highlights two critical issues in app/src/intrusive_list.h: first, moving an empty or unlinked node can leave dangling pointers pointing to the moved-from node; second, moving an empty intrusive_list can cause the sentinel node to point to the destroyed list's sentinel. Code suggestions are provided to resolve both issues.
| if (this != &other) { | ||
| next_->previous_ = previous_; | ||
| previous_->next_ = next_; | ||
| move(other); | ||
| } |
There was a problem hiding this comment.
If other is an empty or unlinked node (i.e., other.next_ == &other), calling move(other) will result in this->next_ and this->previous_ pointing to &other (the moved-from node's address) instead of this. This creates a dangling pointer once other is destroyed or modified, and incorrectly marks this as being in a list. We should handle the empty/unlinked case by making this empty/unlinked as well.
if (this != &other) {
next_->previous_ = previous_;
previous_->next_ = next_;
if (other.next_ == &other) {
next_ = this;
previous_ = this;
} else {
move(other);
}
}| intrusive_list(this_type&& other) noexcept | ||
| : data_(std::move(other.data_)), node_offset_(other.node_offset_) {} | ||
|
|
||
| intrusive_list& operator=(this_type&& other) noexcept { | ||
| data_ = std::move(other.data_); | ||
| node_offset_ = std::move(other.node_offset_); | ||
| if (this != &other) { | ||
| clear(); | ||
| data_ = std::move(other.data_); | ||
| node_offset_ = other.node_offset_; | ||
| } | ||
| return *this; | ||
| } |
There was a problem hiding this comment.
When other is an empty list, other.data_ points to itself. Moving other.data_ directly via std::move(other.data_) can lead to this->data_ pointing to other.data_ (a dangling pointer once other is destroyed), because the move constructor/assignment of intrusive_list_node may not handle the self-pointing sentinel node correctly for empty lists. We should explicitly check if other is empty and only move other.data_ if it contains elements.
intrusive_list(this_type&& other) noexcept
: data_(&data_, &data_), node_offset_(other.node_offset_) {
if (other.data_.next_ != &other.data_) {
data_ = std::move(other.data_);
}
}
intrusive_list& operator=(this_type&& other) noexcept {
if (this != &other) {
clear();
if (other.data_.next_ != &other.data_) {
data_ = std::move(other.data_);
}
node_offset_ = other.node_offset_;
}
return *this;
}…trusive_list logic edits
| : data_(&data_, &data_), node_offset_(offset_of_node(node_member)) {} | ||
|
|
||
| #if defined(FIREBASE_USE_MOVE_OPERATORS) | ||
| intrusive_list(this_type&& other) noexcept { *this = std::move(other); } |
There was a problem hiding this comment.
Single-parameter constructors should be marked explicit.
| @@ -82,9 +81,7 @@ class HttpsCallableResult { | |||
| // Only functions are allowed to construct results. | |||
| friend class ::firebase::functions::internal::HttpsCallableReferenceInternal; | |||
| HttpsCallableResult(const Variant& data) : data_(data) {} | |||
There was a problem hiding this comment.
Single-parameter constructors should be marked explicit.
| friend class ::firebase::functions::internal::HttpsCallableReferenceInternal; | ||
| HttpsCallableResult(const Variant& data) : data_(data) {} | ||
| #if defined(FIREBASE_USE_MOVE_OPERATORS) | ||
| HttpsCallableResult(Variant&& data) : data_(std::move(data)) {} |
There was a problem hiding this comment.
Single-parameter constructors should be marked explicit.
Description
Follow-up cleanup from #1958.
Removes the now unconditionally defined
FIREBASE_USE_MOVE_OPERATORSandFIREBASE_USE_STD_FUNCTIONmacros fromapp/src/include/firebase/internal/common.hand unwraps all 90#if/#ifdefguards across 72 files inapp,auth,database,functions, andstorage.Companion Unity SWIG PR (hiding move constructors/assignment operators in Unity
.ifiles instead of adding#ifndef SWIGto C++ headers): firebase/firebase-unity-sdk#1580Summary of Changes
app/src/include/firebase/internal/common.h):#define FIREBASE_USE_MOVE_OPERATORS,#define FIREBASE_USE_STD_FUNCTION, and the follow-upTODOcomment.#include <utility>incommon.hfor transitive compatibility.app/,auth/,database/,functions/,storage/):#if defined(FIREBASE_USE_MOVE_OPERATORS),#ifdef FIREBASE_USE_MOVE_OPERATORS,#if defined(FIREBASE_USE_STD_FUNCTION),#ifdef FIREBASE_USE_STD_FUNCTION, and|| defined(DOXYGEN)guards and matching#endifdirectives with no logic changes.<functional>/<utility>includes into standard Google C++ include order (callback.h,future.h,future_impl.h,transaction.h) and added direct#include <utility>injobject_reference.cc,callable_result.h,intrusive_list.h, andintrusive_list_test.cc.FutureBase::operator=(FutureBase&&)doc comment inapp/src/include/firebase/future.h(previously copy-pasted as"Copy an untyped future.") and convertedMutableData::operator=(MutableData&&)comment indatabase/src/include/firebase/database/mutable_data.hfrom//to///sogenerated_docs_checkstays clean.Testing
Tested Locally (Linux x64 Workstation)
git grep "FIREBASE_USE_MOVE_OPERATORS\|FIREBASE_USE_STD_FUNCTION"returns0matches acrossfirebase-cpp-sdk(and0matches infirebase-unity-sdk).-DFIREBASE_CPP_BUILD_TESTS=ON -DFIREBASE_INCLUDE_FIRESTORE=OFF -DFIREBASE_USE_BORINGSSL=OFF); all 98/98ctestsuites passed (including all 11 affected suites re-run after final edits).g++andclang++-19(-fsyntax-only -Wall -Wextra -Werror) across-std=c++17,-std=c++20,-std=c++23, and-DINTERNAL_EXPERIMENTALwith 0 warnings/errors..ccfiles withaarch64-linux-android21-clang++ -std=c++17on both NDK23.2.8568313and NDK28.2.13676358with 0 errors.firebase-unity-sdk.imodules — 0 functional C# diffs.docs/Doxyfile),bash scripts/gha/check_copyright.sh -gpassed, and GitHub Actionsfile_format_check/generated_docs_check/ Desktop / Android / iOS builds passed.Not Tested Locally (Covered by GitHub Actions CI)
Type of Change
Place an
xthe applicable box:Notes
Release Notessection ofrelease_build_files/readme.md.