Skip to content

[libcu++] Guard tuple and pair against dangling references#9622

Open
miscco wants to merge 4 commits into
NVIDIA:mainfrom
miscco:tuple_from_temporary
Open

[libcu++] Guard tuple and pair against dangling references#9622
miscco wants to merge 4 commits into
NVIDIA:mainfrom
miscco:tuple_from_temporary

Conversation

@miscco

@miscco miscco commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

With the new tuple-like constructors we also get deleted constructors if the user tries to store a reference to a temporary

This is an important source of bugs, so we should adopt this too

@miscco miscco requested a review from a team as a code owner June 29, 2026 08:27
@miscco miscco requested a review from griwes June 29, 2026 08:27
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 29, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved tuple and pair construction/assignment behavior to more reliably reject unsafe cases involving reference binding from temporary values.
    • Refined constructor/assignment overload resolution so forbidden paths are treated as non-viable (including deleted overloads when applicable), reducing ambiguous or incorrect compile-time matches.
  • Tests
    • Added new compile-time coverage for tuple and pair constructibility from temporaries and converter-based inputs, including reference-qualified scenarios.
    • Updated existing diagnostic coverage to align with the refined behavior.

Walkthrough

Updates tuple and pair constructor/assignment selection to distinguish invalid and deleted cases, adds deleted overloads for reference-from-temporary bindings, and expands compile-time tests for tuple and pair constructibility.

Changes

Reference-from-temporary deletion for pair and tuple

Layer / File(s) Summary
SFINAE vocabulary and macro guards
libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h, libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h, libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h, libcudacxx/include/cuda/std/__optional/optional_ref.h, libcudacxx/include/cuda/std/__fwd/tuple.h, thrust/thrust/iterator/detail/tuple_of_iterator_references.h
Adds __select_constructor and __select_assignment enums with __invalid/__deleted predicates, switches the builtin feature checks in these headers to #ifdef _CCCL_BUILTIN_REFERENCE_CONSTRUCTS_FROM_TEMPORARY, and removes tuple-of-iterator-references trait declarations.
tuple_constraints.h: selection-state rewrite
libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
Tuple construction and assignment selection now returns __invalid for disallowed cases and __deleted when reference_constructs_from_temporary_v applies, with updated include dependencies.
tuple.h: deleted constructor overloads
libcudacxx/include/cuda/std/__tuple_dir/tuple.h
Adds deleted variadic, allocator-arg, and tuple-like constructor overloads that participate when the tuple selection trait resolves to __deleted.
pair.h: selection rewrite and deleted constructors
libcudacxx/include/cuda/std/__utility/pair.h
Pair constructibility and assignability selection now returns __invalid/__deleted, and the header adds deleted forwarding and pair-like constructor overloads under the feature macro.
Constructibility tests
libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp, libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp, libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp, libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
Adds tuple and pair from-temporaries compile-time tests, updates one pair reference-construction expectation set, and switches one diagnostic guard to #ifdef.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp (1)

98-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Add pair-source checks to this helper as well.

This only exercises direct-argument and tuple-source construction. The PR also changes the pair-like constructor path in pair.h, so a regression there would still pass this file. Add cuda::std::pair<Args..., LvalueTempConverter> and host std::pair<...> assertions, including the _CCCL_BUILTIN_REFERENCE_CONSTRUCTS_FROM_TEMPORARY negative cases.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 40ec0c9d-0f7a-429f-a368-e527666c5852

📥 Commits

Reviewing files that changed from the base of the PR and between 0d8f162 and eb40511.

📒 Files selected for processing (11)
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp

Comment thread libcudacxx/include/cuda/std/__utility/pair.h
@miscco miscco force-pushed the tuple_from_temporary branch from eb40511 to 7694a79 Compare June 29, 2026 09:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cf6c994b-bcf2-4647-b520-9362d1f5ed2c

📥 Commits

Reviewing files that changed from the base of the PR and between eb40511 and 7694a79.

📒 Files selected for processing (11)
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp
✅ Files skipped from review due to trivial changes (3)
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
🚧 Files skipped from review as they are similar to previous changes (6)
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__utility/pair.h

@miscco miscco force-pushed the tuple_from_temporary branch from 7694a79 to f542cf9 Compare June 29, 2026 09:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp (1)

84-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: add allocator_arg_t constructibility checks here as well. The stack for this PR says tuple gained deleted allocator-arg overloads in addition to the plain variadic and tuple-like forms, but this file only exercises the latter two. A regression in the allocator-aware branch would currently pass unnoticed.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c84d231e-6010-43f2-a228-c1859a944037

📥 Commits

Reviewing files that changed from the base of the PR and between 7694a79 and f542cf9.

📒 Files selected for processing (11)
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp
💤 Files with no reviewable changes (1)
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
✅ Files skipped from review due to trivial changes (4)
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
🚧 Files skipped from review as they are similar to previous changes (4)
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__utility/pair.h

@miscco miscco force-pushed the tuple_from_temporary branch from f542cf9 to 10106da Compare June 29, 2026 11:03
@miscco miscco changed the title [libcu++] Guard tuple and pair against daingling references [libcu++] Guard tuple and pair against dangling references Jun 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5897b602-93c9-4a90-ba50-4e0f89960e90

📥 Commits

Reviewing files that changed from the base of the PR and between f542cf9 and 10106da.

📒 Files selected for processing (11)
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp
💤 Files with no reviewable changes (1)
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
✅ Files skipped from review due to trivial changes (3)
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
🚧 Files skipped from review as they are similar to previous changes (5)
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h

}

#if defined(_CCCL_BUILTIN_REFERENCE_CONSTRUCTS_FROM_TEMPORARY)
#ifdef _CCCL_BUILTIN_REFERENCE_CONSTRUCTS_FROM_TEMPORARY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-1, I don't like this :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe there is a clang-tidy rule about that, but I can revert it

@miscco miscco force-pushed the tuple_from_temporary branch from 10106da to fe52857 Compare June 29, 2026 13:07
@miscco miscco requested a review from a team as a code owner June 29, 2026 13:07
@miscco miscco requested a review from elstehle June 29, 2026 13:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp (1)

84-109: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

suggestion: add allocator_arg_t constructibility checks for the deleted-from-temporary cases here. The PR also changes the allocator-aware tuple constructors, but this file only exercises the plain variadic and tuple-like forms, so regressions in that overload set would still pass unnoticed. As per path instructions, libcudacxx reviews should focus on correctness and API stability, and CCCL test sources should use compile-time checks when relevant for compile-time guarantees.

Sources: Coding guidelines, Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 45d74d9e-6629-46b5-b993-c444211b986a

📥 Commits

Reviewing files that changed from the base of the PR and between 10106da and fe52857.

📒 Files selected for processing (13)
  • libcudacxx/include/cuda/std/__fwd/tuple.h
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/from_temporaries.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/from_temporaries.pass.cpp
  • thrust/thrust/iterator/detail/tuple_of_iterator_references.h
💤 Files with no reviewable changes (3)
  • libcudacxx/include/cuda/std/__fwd/tuple.h
  • thrust/thrust/iterator/detail/tuple_of_iterator_references.h
  • libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/convert_non_const_copy.cpp
✅ Files skipped from review due to trivial changes (4)
  • libcudacxx/include/cuda/std/__type_traits/reference_constructs_from_temporary.h
  • libcudacxx/include/cuda/std/__optional/optional_ref.h
  • libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h
🚧 Files skipped from review as they are similar to previous changes (4)
  • libcudacxx/include/cuda/std/__type_traits/sfinae_traits.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants