public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26581]  New: incomplete (unsized) static array types cannot be completed
@ 2006-03-06 13:33 bernard at brenda-arkle dot demon dot co dot uk
  2006-03-06 13:53 ` [Bug c/26581] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bernard at brenda-arkle dot demon dot co dot uk @ 2006-03-06 13:33 UTC (permalink / raw)
  To: gcc-bugs

If this is (as I am fairly sure) a bug, then it will
surely be a bug in the C front end, and as such be
architecture-independent.

The behaviour here complained of is peculiar to -pedantic,
which chucks an error for what I believe is correct code.
It's not even a warning otherwise, and I think rightly.
The behaviour is seen in gcc-4.0.2 and gcc-4.1, an
may well be older, as I have only recently started to use
-pedantic by default.

BS ISO/IEC 9899:1999 6.2.5 para.22 (first two sentences)
An array type of unknown size is an incomplete type.  It is completed, for an
identifier of
that type, by specifying the size in a later declaration (with internal or
external linkage).

There's a great deal of murk in the Standard, some of which is relevant, but
in this cases at least, m'lud, the law is clear.  Just as one may have

extern int thingy1[];
extern int thingy1[1];

one may have (with file scope, not block scope)

static int thingy2[];
static int thingy2[1];

gcc is happy with the 'extern' version, but not with the 'static' ones:
it gags, claiming that the first declaration is bad ("array size missing")
and the second is inconsistent with it ("conflicting types").
Perhaps the much stricter rules for block-scope declarations confused
the implementers?  Specifically, objects other than function parameters
declared in a block which are not explicitly given the storage-class
'extern' have no linkage  (Standard 6.2.2 para. 6), and an object with
no linkage may not have an incomplete type declaration (6.7 para. 7).
The reason for this restriction escapes me (why on earth not allow
deferred type completion here too?).

This is not the end of the story, but I'm steering clear of the
full horrors of 'extern' in this particular bug report.

I have not found a comparable problem with other incomplete types
(pointers to incompletely defined struct types, &c.), irrespective
of linkage.

Bernard Leak
--
What's wrong with a recursive dmalloc, anyway?


-- 
           Summary: incomplete (unsized) static array types cannot be
                    completed
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bernard at brenda-arkle dot demon dot co dot uk
 GCC build triplet: (same)
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: (same)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
@ 2006-03-06 13:53 ` pinskia at gcc dot gnu dot org
  2006-03-06 14:07 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-06 13:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-03-06 13:53 -------
Comeau C front-end also rejects this code:
Comeau C/C++ 4.3.3 (Aug  6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing.  All rights reserved.
MODE:strict errors C99 

"ComeauTest.c", line 1: error: incomplete type is not allowed
  static int thingy2[];
             ^

http://www.comeaucomputing.com/tryitout/


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
  2006-03-06 13:53 ` [Bug c/26581] " pinskia at gcc dot gnu dot org
@ 2006-03-06 14:07 ` pinskia at gcc dot gnu dot org
  2006-03-06 14:10 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-06 14:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-03-06 14:06 -------
Not a bug:
>From C99, 6.9.2/3 says:
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. 
------
This is a tentative definition and is internal linkage and in this case the
type incomplete so it is invalid code which is correctly rejected.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
  2006-03-06 13:53 ` [Bug c/26581] " pinskia at gcc dot gnu dot org
  2006-03-06 14:07 ` pinskia at gcc dot gnu dot org
@ 2006-03-06 14:10 ` joseph at codesourcery dot com
  2006-03-06 18:35 ` bernard at brenda-arkle dot demon dot co dot uk
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2006-03-06 14:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from joseph at codesourcery dot com  2006-03-06 14:10 -------
Subject: Re:   New: incomplete (unsized) static array types
 cannot be completed

On Mon, 6 Mar 2006, bernard at brenda-arkle dot demon dot co dot uk wrote:

> static int thingy2[];
> static int thingy2[1];

This contradicts 6.9.2 paragraph 3: "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.".  (Undefined behavior 
since it's not in a Constraints section, so diagnostic not required, but 
as a quality of implementation matter it should be diagnosed at least with 
-pedantic.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
                   ` (2 preceding siblings ...)
  2006-03-06 14:10 ` joseph at codesourcery dot com
@ 2006-03-06 18:35 ` bernard at brenda-arkle dot demon dot co dot uk
  2006-03-06 18:58 ` joseph at codesourcery dot com
  2009-03-30  1:20 ` jsm28 at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: bernard at brenda-arkle dot demon dot co dot uk @ 2006-03-06 18:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bernard at brenda-arkle dot demon dot co dot uk  2006-03-06 18:35 -------
Thanks - I'd forgotten that 'static' declarations can be 
tentative definitions too.  But now I'm even more confused!
As I wrote, unsized arrays do one thing, undefined structs do another
(this is a "gcc fact" whatever its ANSI-legal status).

Consider this:
struct poo; /* declares an incomplete structure type, 6.7.2.3 para. 7 */
static struct poo thingy; /* a tentative definition, 6.9.2 para. 2 */
/* The structure type is still incomplete, 6.7.2.3 para. 3 */
/* any subsequent definition of struct poo is too late */

Shouldn't this now be flagged as an error, at least if '-pedantic'
is requested?

If I'm wrong again about this, I'll shut up...

Bernard Leak
--
I remember when the Standard had fewer than 8 bits' worth of confusing pages!


-- 

bernard at brenda-arkle dot demon dot co dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
                   ` (3 preceding siblings ...)
  2006-03-06 18:35 ` bernard at brenda-arkle dot demon dot co dot uk
@ 2006-03-06 18:58 ` joseph at codesourcery dot com
  2009-03-30  1:20 ` jsm28 at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2006-03-06 18:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from joseph at codesourcery dot com  2006-03-06 18:58 -------
Subject: Re:  incomplete (unsized) static array types cannot be
 completed

On Mon, 6 Mar 2006, bernard at brenda-arkle dot demon dot co dot uk wrote:

> struct poo; /* declares an incomplete structure type, 6.7.2.3 para. 7 */
> static struct poo thingy; /* a tentative definition, 6.9.2 para. 2 */
> /* The structure type is still incomplete, 6.7.2.3 para. 3 */
> /* any subsequent definition of struct poo is too late */
> 
> Shouldn't this now be flagged as an error, at least if '-pedantic'
> is requested?

Yes.  Again, this is a quality-of-implementation issue since the 
requirement is not a Constraint.  I'm already aware of the issue that if 
the struct is subsequently defined there isn't an error here, though I 
don't think there's a bug filed (bug 24293 is related but not the same).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/26581] incomplete (unsized) static array types cannot be completed
  2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
                   ` (4 preceding siblings ...)
  2006-03-06 18:58 ` joseph at codesourcery dot com
@ 2009-03-30  1:20 ` jsm28 at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2009-03-30  1:20 UTC (permalink / raw)
  To: gcc-bugs



-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-03-30 01:20:32
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-03-30  1:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-06 13:33 [Bug c/26581] New: incomplete (unsized) static array types cannot be completed bernard at brenda-arkle dot demon dot co dot uk
2006-03-06 13:53 ` [Bug c/26581] " pinskia at gcc dot gnu dot org
2006-03-06 14:07 ` pinskia at gcc dot gnu dot org
2006-03-06 14:10 ` joseph at codesourcery dot com
2006-03-06 18:35 ` bernard at brenda-arkle dot demon dot co dot uk
2006-03-06 18:58 ` joseph at codesourcery dot com
2009-03-30  1:20 ` jsm28 at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).