🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2612

Definition With Incomplete Type Should Be An Error

#2612
From: Bruce Blodgett
Date: Wed, 27 Mar 1991 21:49
69 lines
2891 bytes
Are my comments about the following program correct?  I feel that that
the declarations of s1 and a2 should ideally require a diagnostic.

static int s1[]; /* Violates a "shall" requirement: */
/*
External Object Definitions 3.7.2 p 84 l 29:  A declaration of an
identifier for an object that has file scope without an initializer,
and ... with the storage-class specifier static, constitutes a
tentative definition.

The declaration of array s1 is a tentative definition.

Linkages of Identifiers 3.1.2.2 p 22 l 14:  If the declaration of a
file scope identifier for an object ... contains the storage-class
specifier static, the identifier has internal linkage.

s1 has internal linkage.

Array Declarators 3.5.4.2 p 68 l 9:  If the size is not present, the
array type is an incomplete type.

Array s1 has incomplete type.

External Object Definitions 3.7.2 p 84 l 35:  If the declaration of
an identifier for an object is a tentative definition and has internal
linkage, the declared type shall not be an incomplete type.

Definitions of Terms 1.6 p 3 l 42:  If a "shall" ... requirement that
appears outside of a constraint is violated, the behavior is
undefined.

Regardless of whether the compilation unit contains any further
references to array s1, this produces undefined behavior.
*/

extern void main(void)
{
    auto int a2[]; /* Undefined behavior? */
/*
Array Declarators 3.5.4.2 p 68 l 9:  If the size is not present, the
array type is an incomplete type.

Array a2 has incomplete type.

Linkages of Identifiers 3.1.2.2 p 22 l 24:  The following
identifiers have no linkage: ...; a block scope identifier for an
object declared without the storage-class specifier extern.

Array a2 has no linkage.

Declarations 3.5 p 58 l 17:  If an identifier has no linkage, there
shall be no more than one declaration of the identifier (in a
declarator or type specifier) with the same scope and in the same name
space....

There shall be no more declarations of array a2 in this scope.  So the
type of array a2 cannot be completed.  So the amount of storage to be
reserved for array a2 cannot be determined.  This is exactly the
reason that the declaration of array s1 violates a "shall" requirement
above.

Regardless of whether the compilation unit contains any further
references to array a2, this declaration should cause the same
severity of diagnostic as the declaration of array s1 above.
*/
}
Bruce Blodgett
blodgett@apollo.hp.com
(508) 256-0176 x4037
Technical Details
Message-ID: <509f2397.20b6d@apollo.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!apollo!blodgett

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!apollo!blodgett
From: blodgett@apollo.HP.COM (Bruce Blodgett)
Newsgroups: comp.std.c,comp.std.c++
Subject: Definition With Incomplete Type Should Be An Error
Message-ID: <509f2397.20b6d@apollo.HP.COM>
Date: 27 Mar 91 21:49:00 GMT
Sender: root@apollo.HP.COM
Lines: 69