public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33101]  New: C++ error on valid code: <anonymous> has incomplete type
@ 2007-08-17 23:32 ian at airs dot com
  2007-08-17 23:33 ` [Bug c++/33101] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: ian at airs dot com @ 2007-08-17 23:32 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

This C++ test case works with gcc 4.1.1.  With gcc 4.2 and with mainline it
gets an inexplicable error.

typedef void v;
typedef v (*pf)(v);

foo.cc:2: error: ‘<anonymous>’ has incomplete type
foo.cc:2: error: invalid use of ‘v’


-- 
           Summary: C++ error on valid code: <anonymous> has incomplete type
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


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


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

* [Bug c++/33101] C++ error on valid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
@ 2007-08-17 23:33 ` pinskia at gcc dot gnu dot org
  2007-08-18  4:19 ` ian at airs dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-17 23:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-08-17 23:33 -------
This is not valid code.

*** This bug has been marked as a duplicate of 9278 ***


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/33101] C++ error on valid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
  2007-08-17 23:33 ` [Bug c++/33101] " pinskia at gcc dot gnu dot org
@ 2007-08-18  4:19 ` ian at airs dot com
  2007-08-18  8:54 ` [Bug c++/33101] Bad C++ error on invalid " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2007-08-18  4:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ian at airs dot com  2007-08-18 04:19 -------
Thanks for the explanation.  That is new to me.

I am now going to reopen this bug because the error message is terrible.  There
is no anonymous or incomplete type here.  gcc should perhaps print something
like

error: invalid use of typedef 'v' in function parameter declaration


-- 

ian at airs dot com changed:

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


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
  2007-08-17 23:33 ` [Bug c++/33101] " pinskia at gcc dot gnu dot org
  2007-08-18  4:19 ` ian at airs dot com
@ 2007-08-18  8:54 ` pinskia at gcc dot gnu dot org
  2007-08-18  9:00 ` schwab at suse dot de
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-18  8:54 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (2 preceding siblings ...)
  2007-08-18  8:54 ` [Bug c++/33101] Bad C++ error on invalid " pinskia at gcc dot gnu dot org
@ 2007-08-18  9:00 ` schwab at suse dot de
  2007-08-18 17:12 ` ian at airs dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: schwab at suse dot de @ 2007-08-18  9:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from schwab at suse dot de  2007-08-18 09:00 -------
The error message makes perfect sense: void is an incomplete type and the
formal parameter has no name.


-- 


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (3 preceding siblings ...)
  2007-08-18  9:00 ` schwab at suse dot de
@ 2007-08-18 17:12 ` ian at airs dot com
  2007-08-18 17:15 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2007-08-18 17:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ian at airs dot com  2007-08-18 17:12 -------
The error message makes some sense if you already understand the issue.  If you
do not know what the problem is, then I believe it is completely obscure.  This
is particularly so since the same code is valid C code.


-- 

ian at airs dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (4 preceding siblings ...)
  2007-08-18 17:12 ` ian at airs dot com
@ 2007-08-18 17:15 ` pinskia at gcc dot gnu dot org
  2007-08-18 17:29 ` fang at csl dot cornell dot edu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-18 17:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2007-08-18 17:15 -------
Here is my quote for today:
Stop programming in C using a C++ compiler.  Learn C+.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (5 preceding siblings ...)
  2007-08-18 17:15 ` pinskia at gcc dot gnu dot org
@ 2007-08-18 17:29 ` fang at csl dot cornell dot edu
  2007-08-18 19:52 ` gdr at cs dot tamu dot edu
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: fang at csl dot cornell dot edu @ 2007-08-18 17:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fang at csl dot cornell dot edu  2007-08-18 17:29 -------
Subject: Re:  Bad C++ error on invalid code: <anonymous> has
 incomplete type

> ------- Comment #5 from pinskia at gcc dot gnu dot org  2007-08-18 17:15 -------
> Here is my quote for today:
> Stop programming in C using a C++ compiler.  Learn C+.

Haha.  And I keep telling people to
"Stop programming in C.  [Period.]  Learn C++."

(ok, that's perhaps too extreme)


-- 


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (6 preceding siblings ...)
  2007-08-18 17:29 ` fang at csl dot cornell dot edu
@ 2007-08-18 19:52 ` gdr at cs dot tamu dot edu
  2007-08-18 22:10 ` ian at airs dot com
  2007-09-08 23:25 ` bangerth at dealii dot org
  9 siblings, 0 replies; 13+ messages in thread
From: gdr at cs dot tamu dot edu @ 2007-08-18 19:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from gdr at cs dot tamu dot edu  2007-08-18 19:52 -------
Subject: Re:  C++ error on valid code: <anonymous> has incomplete type

"ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> writes:

| Thanks for the explanation.  That is new to me.

Check for "abomination" in D&E :-)

| I am now going to reopen this bug because the error message is terrible. 
There
| is no anonymous or incomplete type here.

Well, I believe the parameter is unnamed, and its type is incomplete.

|  gcc should perhaps print something
| like
| 
| error: invalid use of typedef 'v' in function parameter declaration

That is also obscure :-)

Maybe you want

  error: invalid use of typedef-name for type 'void' in a function
         parameter declaration
  note: 'void' can be used as a function parameter only if it appears
        lexically as a keyword

?

-- Gaby


-- 


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (7 preceding siblings ...)
  2007-08-18 19:52 ` gdr at cs dot tamu dot edu
@ 2007-08-18 22:10 ` ian at airs dot com
  2007-09-08 23:25 ` bangerth at dealii dot org
  9 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2007-08-18 22:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from ian at airs dot com  2007-08-18 22:10 -------
Works for me.


-- 

ian at airs dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
  2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
                   ` (8 preceding siblings ...)
  2007-08-18 22:10 ` ian at airs dot com
@ 2007-09-08 23:25 ` bangerth at dealii dot org
  9 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2007-09-08 23:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from bangerth at dealii dot org  2007-09-08 23:24 -------
This sounds good to me to. I guess we can now confirm the PR.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-09-08 23:24:59
               date|                            |


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


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
  2012-03-16 19:32 ` Keith.S.Thompson at gmail dot com
@ 2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com
  1 sibling, 0 replies; 13+ messages in thread
From: Keith.S.Thompson at gmail dot com @ 2012-03-16 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Keith Thompson <Keith.S.Thompson at gmail dot com> 2012-03-16 19:30:17 UTC ---
And since the C++ code is valid, the title of this bug should be changed.


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

* [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
@ 2012-03-16 19:32 ` Keith.S.Thompson at gmail dot com
  2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com
  1 sibling, 0 replies; 13+ messages in thread
From: Keith.S.Thompson at gmail dot com @ 2012-03-16 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

Keith Thompson <Keith.S.Thompson at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Keith.S.Thompson at gmail
                   |                            |dot com

--- Comment #10 from Keith Thompson <Keith.S.Thompson at gmail dot com> 2012-03-16 19:26:45 UTC ---
This came up in a question on stackoverflow.com:

    http://stackoverflow.com/q/9742135/827263

I believe the code is valid. Here's a simpler test case:

    typedef void VOID;
    int main(VOID) { }

which g++ 4.5.2 rejects with the following:

    void_test.cpp:2:10: error: ‘<anonymous>’ has incomplete type
    void_test.cpp:2:14: error: invalid use of ‘VOID’

Quoting N3290, a draft of the 2011 ISO C++ standard, section 8.3.5 [dcl.fct]:

    The parameter-declaration-clause determines the arguments that can
    be specified, and their processing, when the function is called.
    [ ... ] If the parameter-declaration-clause is empty, the function
    takes no arguments. The parameter list (void) is equivalent to
    the empty parameter list. Except for this special case, void
    shall not be a parameter type (though types derived from void,
    such as void*, can).

Earlier versions of the standard have similar or identical wording.

The last sentence implies that "void" here is being used as a type
name, not as some special-case syntactic use of the keyword.  I believe
the phrase "special case" is meant to exclude declarations like

    void foo(void, int);

or 

    void bar(void param);

not to prohibit the use of a typedef.  Since a typedef creates an
*alias* for an existing type, the name "VOID" should be usable as a
replacement for "void" whenever it's used as a type name.

Note that the syntax for a parameter-declaration does not refer
specifically to the "void" keyword; rather, "void" is valid in that
context because it's a type name.

Practically speaking, the purpose of allowing "void" as a parameter
declaration is for compatibility with C.  Quoting the latest draft
of the C standard, N1570 6.7.6.3p10:

    The special case of an unnamed parameter of type void as the only
    item in the list specifies that the function has no parameters.

It refers to the *type* void, not the keyword, implying that a
typedef is acceptable in this context -- and gcc 4.5.2 accepts the
above program without complaint when compiling it as C.

I agree that the C++ standard's wording is ambiguous, and *could*
be read as requiring the keyword "void", but I believe the intent
is to permit a typedef.  (And if you want to argue that the use of
a typedef is silly, I agree completely.)

I believe that the resolution of DR 577:
    http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#577
confirms this.  The resolution, as of August, 2011, suggests changing
the wording to refer to the *type* void rather than the keyword.  
(That change doesn't appear in the N3270 draft; I don't know whether
it appears in the final ISO C++ 2011 standard.)

At the very least, since there is (unfortunately) real-world code that 
depends on this, I suggest changing it from a fatal error to a warning,
though I think removing the diagnostic altogether would be better.


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

end of thread, other threads:[~2012-03-16 19:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-17 23:32 [Bug c++/33101] New: C++ error on valid code: <anonymous> has incomplete type ian at airs dot com
2007-08-17 23:33 ` [Bug c++/33101] " pinskia at gcc dot gnu dot org
2007-08-18  4:19 ` ian at airs dot com
2007-08-18  8:54 ` [Bug c++/33101] Bad C++ error on invalid " pinskia at gcc dot gnu dot org
2007-08-18  9:00 ` schwab at suse dot de
2007-08-18 17:12 ` ian at airs dot com
2007-08-18 17:15 ` pinskia at gcc dot gnu dot org
2007-08-18 17:29 ` fang at csl dot cornell dot edu
2007-08-18 19:52 ` gdr at cs dot tamu dot edu
2007-08-18 22:10 ` ian at airs dot com
2007-09-08 23:25 ` bangerth at dealii dot org
     [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
2012-03-16 19:32 ` Keith.S.Thompson at gmail dot com
2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com

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).