Feature Request: constrain const-qualified variables with register storage class to be initialized

Problem statement

Consider two const-qualified variables, one with register storage class and one auto:

  register unsigned char const oops;
  auto unsigned char const rando;

Since rando doesn't have register class and is unsigned char it could always be evaluated and would provide an unspecific value.

In contrast to that oops can never be used for other effects than to feed it to the sizeof operator. All other access is inhibited by the standard, either as constraint violation or as resulting in undefined behavior:

A compiler can easily detect that such a variable is not initialized at the point of the declaration itself. No complicated flow analysis has to be performed to see if it could have been initialized later or if the underlying object could have been aliased and then assigned with a value.

Proposed modification

After 6.7.9p5 add a new paragraph:

If the declaration of an identifier has register storage class and the type of the declaration is const qualified an initialization of the object shall be provided to form a full definition of the object.

If the feature request to allow for const-qualified variables with register storage class in file scope, the terminating subsentence would be important to clarify that the initializer is expected at any occurence of the declaration of the identifier and thus that there can be only exactly one declaration/definition of it.

This would defer from a static declaration, that first can be given without initialization (thus being only a declaration and not a definition) and then later be defined by providing an initializer. Here a compiler could defer to establish the the value of the object, since he may always refer to the object through its address.

Another, but unsatisfactory solution would be to treat these objects the same as for storage class static and to modify the second phrase of 6.7.9p10

If an object is not initialized explicitly that has static storage duration, thread storage duration, or is of register storage class and of a const qualified type then: ...

Author: Jens Gustedt, INRIA, 2012