Undefined behaviour: (1) Placement `new` done on an existing object without destroying and (2) the return value of placement `new` is discarded

Open Beginner friendly
#301 3 comments 0 reactions 0 assignees View on GitHub

@sankurm is already working on this.

Since Sep 15, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start in score/concurrency/future/interruptible_state.h at lines 82, 102, and 118, then inspect the surrounding lifetime and assignment logic. Check the other placement-new instances noted in the issue and run the existing concurrency/future tests. Done means the reported undefined-behaviour cases are addressed without introducing new object-lifetime problems.

Written by the indexing model from the issue text.

Description

comp-concurrency

The following code on this line:

        new (&value_) score::Result<Value>{std::move(value)};

This has two problems:

  1. The existing object is not destroyed. FYI, the Error type is currently trivially destructible. If this does not hold true in the future, this code would have the undefined behaviour of constructing another object at the same location without destroying the existing object. See this.
  2. The return of the placement new should not be discarded. It is okay to assign it back to value_. To read about the issue see this reference.

It is suggested that either the existing object be destroyed before placement new OR a new object be assigned to the existing one:
Suggested:

        value_ = score::Result<Value>{std::move(value)};  //Preferred

The following is a possible fix but I would discourage it.

        value_->~score::Result<Value>();
        value_ = new (&value_) score::Result<Value>{std::move(value)};

The same issue is observed on all these lines also:

  1. https://github.com/eclipse-score/baselibs/blob/529cd6ba80cc16220e1a3bf1f491736ab07317ea/score/concurrency/future/interruptible_state.h#L102
  2. https://github.com/eclipse-score/baselibs/blob/529cd6ba80cc16220e1a3bf1f491736ab07317ea/score/concurrency/future/interruptible_state.h#L118

It may be worth checking other instances of this error and address, preferably, by creating new issues.

Dominant language
C++
Stars
26
Forks
86
Avg merge
3d 1h
Merged PRs (30d)
41

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eclipse-score/baselibs

All issues in eclipse-score/baselibs

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.