public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 12+ 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] 12+ 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 ` [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type Keith.S.Thompson at gmail dot com
@ 2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com
  2012-03-16 20:39 ` [Bug c++/33101] [DR 577] " redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 12+ 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] 12+ messages in thread

* [Bug c++/33101] [DR 577] 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 ` [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type Keith.S.Thompson at gmail dot com
  2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com
@ 2012-03-16 20:39 ` redi at gcc dot gnu.org
  2012-03-16 20:46 ` [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-16 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Bad C++ error on invalid    |[DR 577] Bad C++ error on
                   |code: <anonymous> has       |invalid code: <anonymous>
                   |incomplete type             |has incomplete type

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-16 20:17:02 UTC ---
(In reply to comment #10)
> 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.)

It doesn't, the DR says [Voted into the WP at the February, 2012 meeting.]
i.e. after the 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.

Since GCC, Clang and EDG all reject it today I'm surprised such real-world code
hasn't been changed already.


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2012-03-16 20:39 ` [Bug c++/33101] [DR 577] " redi at gcc dot gnu.org
@ 2012-03-16 20:46 ` redi at gcc dot gnu.org
  2012-03-16 21:47 ` Keith.S.Thompson at gmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-16 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |rejects-valid
            Summary|[DR 577] Bad C++ error on   |[DR 577] allow typedefs for
                   |invalid code: <anonymous>   |void in empty parameter
                   |has incomplete type         |list

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-16 20:37:33 UTC ---
(In reply to comment #10)
> 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. 

No, that issue confirms quite clearly that before that change (which only
happened last month and is not part of C++98, C++03 or C++11) the code was
definitely invalid:

"The C99 formulation allows typedefs for void, while C++ (and C90) accept only
the keyword itself in this role."

The language was not ambiguous and the intent wasn't clarified by DR 577, the
rule was changed so previously invalid code is now valid.

Subject and keywords changed to match the new status.


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2012-03-16 20:46 ` [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list redi at gcc dot gnu.org
@ 2012-03-16 21:47 ` Keith.S.Thompson at gmail dot com
  2012-03-16 22:54 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: Keith.S.Thompson at gmail dot com @ 2012-03-16 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Keith Thompson <Keith.S.Thompson at gmail dot com> 2012-03-16 21:41:18 UTC ---
On re-reading DR 577, I agree that it implies the current standard
says that only "(void)" is allowed, and in particular that a typedef
is not.  I might have interpreted it differently myself, but I defer to
the committee.  (I thought perhaps that the change had been made between
N3290 and the released standard, but apparently that's not the case.)

The fact that C90 required the keyword further weakens my previous
argument.

So the diagnostic is necessary, but I'd still suggest that a warning
would be more appropriate, and would still meet the current standard's
requirements.

(I should mention that I have no need for this myself; I don't even take
advantage of the permission to use "(void)" rather than "()".)


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2012-03-16 21:47 ` Keith.S.Thompson at gmail dot com
@ 2012-03-16 22:54 ` redi at gcc dot gnu.org
  2014-06-12 14:09 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-16 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-16 21:46:05 UTC ---
(In reply to comment #14)
> (I thought perhaps that the change had been made between
> N3290 and the released standard, but apparently that's not the case.)

See the text in bold at the top of the issues list:
"Issues with DR and WP status are NOT part of the International Standard for
C++."

> The fact that C90 required the keyword further weakens my previous
> argument.
> 
> So the diagnostic is necessary, but I'd still suggest that a warning
> would be more appropriate, and would still meet the current standard's
> requirements.

The current standard is C++11, that change is only in the current *draft* and
that's not a standard.

> (I should mention that I have no need for this myself; I don't even take
> advantage of the permission to use "(void)" rather than "()".)

Good, it's an abomination!


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2012-03-16 22:54 ` redi at gcc dot gnu.org
@ 2014-06-12 14:09 ` paolo.carlini at oracle dot com
  2014-06-14 22:56 ` paolo at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-12 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|gcc-bugs at gcc dot gnu.org        |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com
   Target Milestone|---                         |4.10.0

--- Comment #16 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Let's resolve this.


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2014-06-12 14:09 ` paolo.carlini at oracle dot com
@ 2014-06-14 22:56 ` paolo at gcc dot gnu.org
  2014-06-14 23:00 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-06-14 22:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #17 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Sat Jun 14 22:55:40 2014
New Revision: 211673

URL: https://gcc.gnu.org/viewcvs?rev=211673&root=gcc&view=rev
Log:
/cp
2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/33101
    * decl.c (grokparms): Improve error message about void parameters.
    * error.c (type_to_string): Fix aka cut off code.

/testsuite
2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/33101
    * g++.dg/other/void3.C: New.
    * g++.dg/conversion/err-recover1.C: Update.

Added:
    trunk/gcc/testsuite/g++.dg/other/void3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/error.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/conversion/err-recover1.C


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2014-06-14 22:56 ` paolo at gcc dot gnu.org
@ 2014-06-14 23:00 ` paolo.carlini at oracle dot com
  2014-06-14 23:06 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-14 23:00 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
           Assignee|paolo.carlini at oracle dot com    |unassigned at gcc dot gnu.org

--- Comment #18 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2014-06-14 23:00 ` paolo.carlini at oracle dot com
@ 2014-06-14 23:06 ` paolo.carlini at oracle dot com
  2014-06-23 17:06 ` paolo at gcc dot gnu.org
  2014-06-23 17:08 ` paolo.carlini at oracle dot com
  11 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-14 23:06 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #19 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Oops, I think the DR577 proper bit isn't done yet ;)


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2014-06-14 23:06 ` paolo.carlini at oracle dot com
@ 2014-06-23 17:06 ` paolo at gcc dot gnu.org
  2014-06-23 17:08 ` paolo.carlini at oracle dot com
  11 siblings, 0 replies; 12+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-06-23 17:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #20 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Mon Jun 23 17:05:33 2014
New Revision: 211906

URL: https://gcc.gnu.org/viewcvs?rev=211906&root=gcc&view=rev
Log:
/cp
2014-06-23  Paolo Carlini  <paolo.carlini@oracle.com>

    DR 577
    PR c++/33101
    * decl.c (grokparms): Accept a single parameter of type 'void'.

/testsuite
2014-06-23  Paolo Carlini  <paolo.carlini@oracle.com>

    DR 577
    PR c++/33101
    * g++.dg/other/void1.C: Adjust.
    * g++.dg/other/void3.C: Likewise.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/other/void1.C
    trunk/gcc/testsuite/g++.dg/other/void3.C


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

* [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list
       [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2014-06-23 17:06 ` paolo at gcc dot gnu.org
@ 2014-06-23 17:08 ` paolo.carlini at oracle dot com
  11 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-23 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #21 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2014-06-23 17:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-33101-4@http.gcc.gnu.org/bugzilla/>
2012-03-16 19:32 ` [Bug c++/33101] Bad C++ error on invalid code: <anonymous> has incomplete type Keith.S.Thompson at gmail dot com
2012-03-16 19:40 ` Keith.S.Thompson at gmail dot com
2012-03-16 20:39 ` [Bug c++/33101] [DR 577] " redi at gcc dot gnu.org
2012-03-16 20:46 ` [Bug c++/33101] [DR 577] allow typedefs for void in empty parameter list redi at gcc dot gnu.org
2012-03-16 21:47 ` Keith.S.Thompson at gmail dot com
2012-03-16 22:54 ` redi at gcc dot gnu.org
2014-06-12 14:09 ` paolo.carlini at oracle dot com
2014-06-14 22:56 ` paolo at gcc dot gnu.org
2014-06-14 23:00 ` paolo.carlini at oracle dot com
2014-06-14 23:06 ` paolo.carlini at oracle dot com
2014-06-23 17:06 ` paolo at gcc dot gnu.org
2014-06-23 17:08 ` paolo.carlini at oracle 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).