Issue 0444: Issues with alignment in C11, part 1

This issue has been automatically converted from the original issue lists and some formatting may not have been preserved.

Authors: WG 14, Joseph Myers
Date: 2013-07-23
Reference document: N1731
Submitted against: C11 / C17
Status: Fixed
Fixed in: C17
Converted from: n2396.htm

Summary

There are various deficiencies in the C11 text about alignment requirements.

Issue 1: Existence of over-aligned types

6.2.8#3 defines the concept of an over-aligned type, with a footnote saying "Every over-aligned type is, or contains, a structure or union type with a member to which an extended alignment has been applied.". But there is no way in the syntax to apply such an alignment to a member. _Alignas appears in the syntax for alignment-specifier, which in turn appears in that for declaration-specifiers (6.7#1). But structure and union members instead use struct-declaration which uses specifier-qualifier-list which doesn't include a case for alignment-specifier at all. So for the reference to over-aligned types, and the reference in 6.7.5#6 to the "declared object or member", to be meaningful, something needs adding to the syntax for struct-declaration. (Note that specifier-qualifier-list is also used in the syntax for type-name, and it seems less likely that a type-name was intended to be able to include alignment-specifiers.)


Comment from WG14 on 2017-11-03:

Oct 2013 meeting

Committee Discussion

Apr 2014 meeting

Committee Discussion

Oct 2014 meeting

Committee Discussion

There still has not been adequate review of these changes. The Project Editor and others have been asked to examine these changes closely prior to our next meeting.

Apr 2015 meeting

Committee Discussion

The suggested syntax provided by the author has been adopted on a trial basis in at least one implementation. It does not, however, provide for compound literals.

A simpler syntax change was discussed, to wit

specifier-qualifier-list:

type-specifier specifier-qualifier-listopt

type-qualifier specifier-qualifier-listopt

alignment-specifier specifier-qualifier-listopt

where specifier-qualifier-list is used in the grammar in only two productions: struct-declaration (which relates to the primary purpose of this DR), and type-name, which is used only in the definitions of these constructs:

A constraint could be added to 6.7.7 type-name after paragraph 1 disallowing the use of alignment-specifier in a type-name except in the case of compound literal which was deemed useful by the committee. The following principles were elucidated:

In 6.7.3p5, there are two references to specifier-qualifier-list, which should also reference declaration specifiers.

In 6.7.5 paragraphs 2 and 4, there are occurrences of the phrase “alignment attribute” which should instead read “alignment specifier”

Oct 2015 meeting

Committee Discussion

The committee did not discuss the direction from the last meeting in any substantial manner. It has solicited a paper from the author of the direction expressing these ideas as a Suggested Technical Corrigendum.

Apr 2016 meeting

Committee Discussion

A new paper N2028 was submitted that embodied the direction above and the committee accepted it.

Oct 2016 meeting

Committee Discussion

It was noted that C++ allows one additional production for alignment-specifier between struct and tag.

The paper N2028 was presented which had an alternate suggestion for a resolution, but the committee preferred the following.

Proposed Technical Correigendum

Change 6.7.2.1p1 from

specifier-qualifier-list:

type-specifier specifier-qualifier-listopt

type-qualifier specifier-qualifier-listopt

to

specifier-qualifier-list:

type-specifier specifier-qualifier-listopt

type-qualifier specifier-qualifier-listopt

alignment-specifier specifier-qualifier-listopt

Change 6.7.5p2 from

An alignment attribute shall not be specified in a declaration of a typedef, or a bit-field, or a function, or a parameter, or an object declared with the register storage-class specifier.

to

An alignment specifier shall appear only in the declaration specifiers of a declaration, or in the specifier-qualifier list of a member declaration, or in the type name of a compound literal. An alignment specifier shall not be used in conjunction with either of the storage-class specifiers typedef or register, nor in a declaration of a function or bit-field.

Change 6.7.3p5 from

If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once. If other qualifiers appear along with the _Atomic qualifier in a specifier-qualifier-list, the resulting type is the so-qualified atomic type.

to

If the same qualifier appears more than once in the same specifier-qualifier-list or as declaration-specifiers, either directly or via one or more typedefs, the behavior is the same as if it appeared only once. If other qualifiers appear along with the _Atomic qualifier the resulting type is the so-qualified atomic type.

Change 6.7.5p4 from

The combined effect of all alignment attributes in a declaration shall not...

to

The combined effect of all alignment specifiers in a declaration shall not...