Skip to content

[atomics.types.operations] Possibly unintended example #8715

@frederick-vs-ja

Description

@frederick-vs-ja

The example in [atomics.types.operations] Note 8 currently reads:

union pony {
  double celestia = 0.;
  short luna;       // padded
};
atomic<pony> princesses = {};

bool party(pony desired) {
  pony expected;
  return princesses.compare_exchange_strong(expected, desired);
}

In common implementations, pony have the same size as double and a default- or value-initialized pony doesn't have any bit with indeterminate value. So it's questionable to me whether this example serves its purpose. Would it make more sense to initialize the short member instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions