GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(common): do not move from non-const lvalue Options in GroupOptions by ajayky-os · Pull Request #16601 · googleapis/google-cloud-cpp

Conversation

@ajayky-os

@ajayky-os ajayky-os commented Oct 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug in google::cloud::internal::GroupOptions(Options& bundle, Tail&&... t) (google/cloud/internal/group_options.h) where passing a non-const lvalue google::cloud::Options variable silently moved out of the caller's Options object on the first call, leaving it empty for subsequent calls.

Root Cause

In google/cloud/internal/group_options.h, the non-const lvalue reference overload was defined as:

template <typename... Tail>
Options GroupOptions(Options& bundle, Tail&&... t) {
  return google::cloud::internal::MergeOptions(
      GroupOptions(std::forward<Tail>(t)...), std::move(bundle));
}

Because MergeOptions(Options a, Options b) accepts its parameters by value, std::move(bundle) invokes Options(Options&&) on the caller's lvalue bundle, stealing its internal std::unordered_map (m_) and leaving the caller's variable empty.

Minimal PoC & Before/After Output

#include "google/cloud/internal/group_options.h"
#include "google/cloud/options.h"
#include <chrono>
#include <iostream>

struct TimeoutOption {
  using Type = std::chrono::seconds;
};

// Mirrors `storage::Client::SpanOptions` in `google/cloud/storage/client.h`:
template <typename... RequestOptions>
void SimulateGetObjectMetadata(int call_num,
                               google::cloud::Options const& client_defaults,
                               RequestOptions&&... o) {
  google::cloud::Options merged = google::cloud::internal::GroupOptions(
      client_defaults, std::forward<RequestOptions>(o)...);
  std::cout << "  Call #" << call_num
            << " -> effective TimeoutOption = "
            << merged.get<TimeoutOption>().count() << "s\n";
}

int main() {
  google::cloud::Options const client_defaults =
      google::cloud::Options{}.set<TimeoutOption>(std::chrono::seconds(120));

  // Non-const lvalue Options variable with a 30s per-call override:
  google::cloud::Options per_call_opts =
      google::cloud::Options{}.set<TimeoutOption>(std::chrono::seconds(30));

  for (int i = 1; i <= 3; ++i) {
    SimulateGetObjectMetadata(i, client_defaults, per_call_opts);
    std::cout << "    After Call #" << i
              << ": per_call_opts.has<TimeoutOption>() = " << std::boolalpha
              << per_call_opts.has<TimeoutOption>() << "\n";
  }
}

Before this PR (origin/main):

  Call #1 -> effective TimeoutOption = 30s
    After Call #1: per_call_opts.has<TimeoutOption>() = false
  Call #2 -> effective TimeoutOption = 120s
    After Call #2: per_call_opts.has<TimeoutOption>() = false
  Call #3 -> effective TimeoutOption = 120s
    After Call #3: per_call_opts.has<TimeoutOption>() = false

After this PR:

  Call #1 -> effective TimeoutOption = 30s
    After Call #1: per_call_opts.has<TimeoutOption>() = true
  Call #2 -> effective TimeoutOption = 30s
    After Call #2: per_call_opts.has<TimeoutOption>() = true
  Call #3 -> effective TimeoutOption = 30s
    After Call #3: per_call_opts.has<TimeoutOption>() = true

Fix

Pass bundle without std::move in GroupOptions(Options& bundle, Tail&&... t) so that non-const lvalue Options objects are copied, while preserving std::move(bundle) in the rvalue GroupOptions(Options&& bundle, Tail&&... t) overload.

Testing

  • Added MakeOptionSpanTest.NonConstLvalueOptionsPreserved in google/cloud/internal/group_options_test.cc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@ajayky-os
fix(common): do not move from non-const lvalue Options in GroupOptions
dba7ae1
`GroupOptions(Options& bundle, Tail&&... t)` previously passed
`std::move(bundle)` to `MergeOptions(Options, Options)`, which takes its
arguments by value. When a caller passed a non-`const` lvalue `Options`
variable (e.g., to `storage::Client` methods via `Client::SpanOptions`),
the first call moved out of the caller's `Options` variable, leaving it
empty for all subsequent calls.

Pass `bundle` without `std::move` in the `Options&` overload so
non-`const` lvalue `Options` objects are copied and preserved across
calls, while keeping `std::move(bundle)` for the `Options&&` rvalue
overload.
@ajayky-os
ajayky-os deployed to false October 28, 2026 07:32 — with GitHub Actions Active
@ajayky-os ajayky-os mentioned this pull request Oct 28, 2026
fix(storage): apply TransferStallTimeoutOption deadline to unary gRPC calls #16600
Merged
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Oct 28, 2026
View reviewed changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies GroupOptions in google/cloud/internal/group_options.h to avoid moving from a non-const lvalue Options reference, ensuring the original object is preserved. A new unit test has been added to verify this behavior. I have no feedback to provide as the changes are correct and align with the style guide.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.36%. Comparing base (e2ca123) to head (dba7ae1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16601      +/-   ##
==========================================
- Coverage   92.39%   92.36%   -0.04%     
==========================================
  Files        2266     2266              
  Lines      220143   220154      +11     
==========================================
- Hits       203408   203338      -70     
- Misses      16735    16816      +81     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch was successfully deployed

1 active deployment
false — dba7ae17 Deployed Oct 28, 2026 by ajayky-os via Save PR ref #12679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ajayky-os
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.