Discussion:
Using a typedef to void for an empty parameter list produces an error - gcc-4.2 bug?
(too old to reply)
Philipp Reh
2007-05-20 23:48:30 UTC
Permalink
Dear group,

I recently tried gcc-4.2 with some of my code. When compiling something
that includes headers of 'devil' it complains about the following
(narrowed down) case:

typedef void ILvoid;

ILvoid f(ILvoid);

int main()
{
}

It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".
The error message is:

"error: '<anonymous>' has incomplete type"
"error: invalid use of 'ILvoid'"

for in the line delcaring f.

So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?

Cheers,
Philipp Reh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Alberto Ganesh Barbati
2007-05-21 04:56:13 UTC
Permalink
Post by Philipp Reh
typedef void ILvoid;
ILvoid f(ILvoid);
int main()
{
}
It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".
"error: '<anonymous>' has incomplete type"
"error: invalid use of 'ILvoid'"
for in the line delcaring f.
So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?
I would say that the code is ill-formed and gcc is correct. The standard
says in 8.3.5/2 that "The parameter list (void) is equivalent to the
empty parameter list." Even if T is a typedef for void, (T), as a
sequence of tokens, is not the same as (void), therefore the special
case doesn't apply.

HTH,

Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Mathias Gaunard
2007-05-21 04:58:18 UTC
Permalink
Post by Philipp Reh
typedef void ILvoid;
ILvoid f(ILvoid);
int main()
{
}
It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".
[...]
So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?
I don't know whether it's right or wrong, but I wouldn't really expect
this to work.

T foo(void) is really something specific. It doesn't mean that the
function takes a first argument of type void, it means it takes no
argument.

By the way, that feature is deprecated and only available for C
compatibility. You'd better write T foo()
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Alberto Ganesh Barbati
2007-05-21 11:20:53 UTC
Permalink
Post by Mathias Gaunard
T foo(void) is really something specific. It doesn't mean that the
function takes a first argument of type void, it means it takes no
argument.
By the way, that feature is deprecated and only available for C
compatibility. You'd better write T foo()
It's true that C++ programmers are encouraged to avoid this feature,
but, strictly speaking, it has not yet been formally deprecated. The
list of formally deprecated features is in annex D of the standard.

Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Loading...