[S] Change in code/re2[main]: Document why `RE2` objects are neither copyable nor movable.

5 views
Skip to first unread message

Paul Wankadia (Gerrit)

unread,
Aug 24, 2022, 3:20:26 AM8/24/22
to Paul Wankadia, re2...@googlegroups.com

Paul Wankadia has uploaded this change for review.

View Change

Document why `RE2` objects are neither copyable nor movable.

Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
---
M re2/re2.h
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/re2/re2.h b/re2/re2.h
index 4699a7d..d604f1c 100644
--- a/re2/re2.h
+++ b/re2/re2.h
@@ -280,6 +280,20 @@
RE2(const StringPiece& pattern, const Options& options);
~RE2();

+ // Not copyable.
+ // RE2 objects are expensive. You should probably use std::shared_ptr<RE2>
+ // instead. If you really must copy, RE2(first.pattern(), first.options())
+ // effectively does so: it produces a second object that mimics the first.
+ RE2(const RE2&) = delete;
+ RE2& operator=(const RE2&) = delete;
+ // Not movable.
+ // RE2 objects are thread-safe and logically immutable. You should probably
+ // use std::unique_ptr<RE2> instead. Otherwise, consider std::deque<RE2> if
+ // direct emplacement into a container is desired. If you really must move,
+ // be prepared to submit a design document along with your feature request.
+ RE2(RE2&&) = delete;
+ RE2& operator=(RE2&&) = delete;
+
// Returns whether RE2 was created properly.
bool ok() const { return error_code() == NoError; }

@@ -777,9 +791,6 @@
mutable std::once_flag rprog_once_;
mutable std::once_flag named_groups_once_;
mutable std::once_flag group_names_once_;
-
- RE2(const RE2&) = delete;
- RE2& operator=(const RE2&) = delete;
};

/***** Implementation details *****/

To view, visit change 60410. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: re2
Gerrit-Branch: main
Gerrit-Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
Gerrit-Change-Number: 60410
Gerrit-PatchSet: 1
Gerrit-Owner: Paul Wankadia <jun...@google.com>
Gerrit-MessageType: newchange

Perry Lorier (Gerrit)

unread,
Aug 24, 2022, 11:19:03 AM8/24/22
to Paul Wankadia, Randall Bosetti, re2...@googlegroups.com

Attention is currently required from: Paul Wankadia.

Patch set 1:Code-Review +1

View Change

    To view, visit change 60410. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: re2
    Gerrit-Branch: main
    Gerrit-Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
    Gerrit-Change-Number: 60410
    Gerrit-PatchSet: 1
    Gerrit-Owner: Paul Wankadia <jun...@google.com>
    Gerrit-Reviewer: Perry Lorier <per...@google.com>
    Gerrit-CC: Randall Bosetti <r...@google.com>
    Gerrit-Attention: Paul Wankadia <jun...@google.com>
    Gerrit-Comment-Date: Wed, 24 Aug 2022 15:18:59 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Paul Wankadia (Gerrit)

    unread,
    Aug 24, 2022, 11:19:55 AM8/24/22
    to Paul Wankadia, Perry Lorier, Randall Bosetti, re2...@googlegroups.com

    Patch set 1:Code-Review +2

    View Change

      To view, visit change 60410. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: re2
      Gerrit-Branch: main
      Gerrit-Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
      Gerrit-Change-Number: 60410
      Gerrit-PatchSet: 1
      Gerrit-Owner: Paul Wankadia <jun...@google.com>
      Gerrit-Reviewer: Paul Wankadia <jun...@google.com>
      Gerrit-Reviewer: Perry Lorier <per...@google.com>
      Gerrit-CC: Randall Bosetti <r...@google.com>
      Gerrit-Comment-Date: Wed, 24 Aug 2022 15:19:49 +0000

      Paul Wankadia (Gerrit)

      unread,
      Aug 24, 2022, 11:19:59 AM8/24/22
      to Paul Wankadia, Perry Lorier, Randall Bosetti, re2...@googlegroups.com

      Paul Wankadia submitted this change.

      View Change


      Approvals: Paul Wankadia: Looks good to me, approved Perry Lorier: Looks good to me, but someone else must approve
      Document why `RE2` objects are neither copyable nor movable.

      Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
      Reviewed-on: https://code-review.googlesource.com/c/re2/+/60410
      Reviewed-by: Perry Lorier <per...@google.com>
      Reviewed-by: Paul Wankadia <jun...@google.com>
      ---
      M re2/re2.h
      1 file changed, 26 insertions(+), 3 deletions(-)

      To view, visit change 60410. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: re2
      Gerrit-Branch: main
      Gerrit-Change-Id: Icf86a2e12f4f860bd6406b1326324d987659413f
      Gerrit-Change-Number: 60410
      Gerrit-PatchSet: 2
      Gerrit-Owner: Paul Wankadia <jun...@google.com>
      Gerrit-Reviewer: Paul Wankadia <jun...@google.com>
      Gerrit-Reviewer: Perry Lorier <per...@google.com>
      Gerrit-CC: Randall Bosetti <r...@google.com>
      Gerrit-MessageType: merged
      Reply all
      Reply to author
      Forward
      0 new messages