Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWG2840 [basic.align] Missing requirements for fundamental alignments #412

Open
frederick-vs-ja opened this issue Aug 31, 2023 · 3 comments

Comments

@frederick-vs-ja
Copy link

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [basic.align]

Link to reflector thread (if any):

Issue description:
Given class definition struct B { long double d; }; (or any class definition in which alignas is not involved), these doesn't seem to be a rule forbidding B to have an extended alignment.

The issue was found and fixed in C (DR445).

Suggested resolution:

Change [basic.align] p2 as indicated:

A fundamental alignment is represented by an alignment less than or equal to the greatest alignment supported by the implementation in all contexts, which is a valid alignment less than or equal to equal to alignof(std​::​max_align_t) ([support.types]). Fundamental alignments shall be supported by the implementation for objects of all storage durations ([basic.stc]).The alignment required for a type may be different when it is used as the type of a complete object and when it is used as the type of a subobject.
[Example 1: [...] — end example]
The result of the alignof operator reflects the alignment requirement of the type in the complete-object case.

Change [basic.align] p3 as indicated:

An extended alignment is represented by an alignment greater than alignof(std​::​max_align_t). It is implementation-defined whether any extended alignments are supported and the contexts in the storage durations of objects for which they are supported ([dcl.align]). [...]

Add a note after [basic.align] p3 Note1:

[Note X: The strictest supported alignment can be different for objects with different storage durations. — end note]

Add a new paragraph after [basic.align] p3:

X. The alignment requirements of the following types are fundamental alignments:

  • all basic types;
  • all array types whose element type has a fundamental alignment requirement;
  • all class types
    • none of whose non-static data members has a type with an extended alignment requirement,
    • none of whose non-static data members has an alignment-specifier ([dcl.align]) specifying an extended alignment, and
    • none of whose base classes has an extended alignment requirement.

Change [basic.align] p4 as indicated:

[...] Valid alignments include only those values returned by an alignof expression for the fundamental types fundamental alignments plus an additional implementation-defined set of values, which may be empty. [...]

Change [dcl.align] p2.2 as indicated:

if the constant expression does not evaluate to an alignment value ([basic.align]), or evaluates to an extended alignment and the implementation does not support that alignment in the context of the declaration for an object of the storage duration, if any, being declared, the program is ill-formed.

@jensmaurer
Copy link
Member

CWG2840

@jensmaurer jensmaurer changed the title [basic.align] Missing requirements for fundamental alignments CWG2840 [basic.align] Missing requirements for fundamental alignments Dec 13, 2023
@t3nsor
Copy link

t3nsor commented Dec 13, 2023

I think the first bullet should actually say "a scalar type".

@jensmaurer
Copy link
Member

Indeed. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants