On 06/14/2018 02:37 PM, Joseph Myers wrote:
On Thu, 14 Jun 2018, Martin Sebor wrote:

Hmm, I thought fileptr_type_node was a node for FILE*, but it's
actually the same as ptr_type_node, i.e., void*, so the built-in
fprintf expects a void* argument (and declaring it to take a FILE*
triggers the new warning).  That seems odd.  What purpose does it
serve?  (AFAICS, it's not used anywhere except jit).

I would expect fileptr_type_node to be set to correspond to
FILE* once FILE is declared.  Why is that not done?

The built-in functions (which use fileptr_type_node via BT_FILEPTR in
builtin-types.def) are defined long before any definition of FILE is
known.  FILE may be a macro not just a typedef, and the user is free to
have an unrelated definition of FILE if they don't include <stdio.h> or
another standard header defining FILE in that translation unit.

Okay, thanks for the explanation.  I realize the built-ins
are declared before any other declarations have been seen
but I'm not sure I completely agree with everything else
you said.

The standard says FILE is a type so I don't think it can
be a macro that expands to something other than a type
named FILE.  The spec doesn't prevent programs from
#undef-ing FILE so implementations cannot define it as
one and rely on it staying defined(*).  So even if FILE
is a macro, it still (also) has to be an identifier of
a type with that name.

FILE can be a typedef for some other type, but I'm not sure
I see how that creates a problem.  fileptr_type_node could
refer to anything at all (even ptr_type_node) initially and
be set to refer to the first file-scope type or typedef
named FILE seen in a translation unit.  It shouldn't matter
if that happens to be a type that's unrelated to the stdio
FILE.  Is there something I'm missing that makes this approach
not feasible?  (If I'm wrong about FILE being a macro to some
unrelated name then that would sink this idea.)

Martin

[*] By referring to the first group of identifiers I assume
7.1.3, p3 refers to macros specified to be defined in standard
headers, i.e., bullet 3 on the list above.  The second group
of identifiers that can be defined as macros on that list (in
bullet 6) refers to other identifiers such as functions and
types, and those are not subject to paragraph 3.  Do you read
it differently?

Reply via email to