This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11701] New: Typeof problems in detecting whether its argument is a type or an expression
- From: "gccbugs at contacts dot eelis dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Jul 2003 03:04:17 -0000
- Subject: [Bug c++/11701] New: Typeof problems in detecting whether its argument is a type or an expression
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11701
Summary: Typeof problems in detecting whether its argument is a
type or an expression
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gccbugs at contacts dot eelis dot net
CC: gcc-bugs at gcc dot gnu dot org
Typeof accepts two kinds of arguments: types and expressions. In some cases,
typeof interprets (or attempts to interpret) its argument as a type when it
could just as well be an expression. In some extreme cases it (unsuccesfully)
attempts to interpret arguments that can only be interpreted as expressions as
types. As an example of the latter, consider:
struct S { int operator() (); };
typedef typeof(S()()) T;
This code fails to compile, g++ prints: "`type name' declared as function
returning a function". Apparently typeof tries to interpret 'S()()' as a type
name, and fails. However, S()() is a valid expression and I believe typeof
should evaluate to the type of that expression: int.
As an example of an ambiguous but less dramatic situation, consider:
struct S {};
typedef typeof(S()) U;
U u = "hmm";
This code fails to compile, g++ prints: "function `S u()' is initialized like a
variable". This time, typeof's argument could be interpreted either as type or
as an expression, but the ambiguity is ignored and the argument is interpreted
as a type.
The two problems here are (as far as I can tell):
a. typeof's algorithm used to detect whether its argument is a type or an
expression is flawed;
b. in case of ambiguity typeof 'prefers' to interpret its argument as a type,
which seems rather strange to me considering the main purpose of the typeof
facility.