Re: sizeof
Russell Shaw <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <[email protected]> |
Andreas Schwab wrote:
>On Mai 11 2022, Russell Shaw wrote:
>
>> "int()" is not an expression, but a type-id for a function pointer "int(*)()"
>
>Where does it say that?
*****************
7.2 Properties of expressions
7.2.1 Value category
2) Every expression belongs to exactly one of the fundamental classifications in
this taxonomy: lvalue, xvalue, or prvalue. This property of an expression is
called its value category.
*****************
Does "int()" look like a lvalue, xvalue, or prvalue ?
*****************
9.3.3 Ambiguity resolution [dcl.ambig.res]
1)
...
Just as for the ambiguities mentioned in 8.9, the resolution is to consider any
construct that matches the syntax of a declaration to be a declaration.
*****************
Note that a type-id is a declaration syntax.
The parameter "int()" of "void f(int())" is a type-id because:
template-parameter :
type-parameter
type-parameter :
type-parameter-key identifier(opt) = type-id
Therefore, decaying "int()" to "int(*)()" is not performed on an expression, so
none of the prohibitions about standard conversions (an expression concept) applies.
*****************
9.3.3 Ambiguity resolution [dcl.ambig.res]
2)
...
void foo(signed char a)
{
sizeof(int()); // type-id (ill-formed)
...
}
*****************
The standard has an error because "int()" is a valid type-id
void f(int());