[all-commits] [llvm/llvm-project] 07443e: [libc++][test] Improve ThrowingT to Accurately Thr...

Peng Liu via All-commits all-commits at lists.llvm.org
Tue Nov 5 08:24:29 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 07443e9776f97090a776cba0288d65e90b6f1af4
      https://github.com/llvm/llvm-project/commit/07443e9776f97090a776cba0288d65e90b6f1af4
  Author: Peng Liu <winner245 at hotmail.com>
  Date:   2024-11-05 (Tue, 05 Nov 2024)

  Changed paths:
    M libcxx/test/std/containers/sequences/vector/vector.cons/exceptions.pass.cpp

  Log Message:
  -----------
  [libc++][test] Improve ThrowingT to Accurately Throw after throw_after > 1 Use (#114077)

This PR fixes the `ThrowingT` class, which currently fails to raise
exceptions after a specified number of copy construction operations. The
class is intended to throw in a controlled manner based on a specified
counter value `throw_after`. However, its current implementation of the
copy constructor fails to achieve this goal.

The problem arises because the copy constructor does not initialize the
`throw_after_n_` member, leaving `throw_after_n_` to default to `nullptr`
as defined by the in-class initializer. As a result, its copy constructor
always checks against `nullptr`, causing an immediate exception rather
than throwing after the specified number `throw_after` of uses. The fix
is straightforward: simply initialize the `throw_after_n_` member in the
member initializer list.

This issue was previously uncovered because all exception tests for
`std::vector` in `exceptions.pass.cpp` used a `throw_after` value of 1,
which coincidentally aligned with the class's behavior.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list