public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Roger Sayle <roger@eyesopen.com>
To: Gabriel Dos Reis <gdr@integrable-solutions.net>
Cc: jason@redhat.com, <gcc@gcc.gnu.org>
Subject: Re: C++: Anticipated declaration of builtins.
Date: Mon, 26 May 2003 02:44:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.44.0305251921330.5055-100000@www.eyesopen.com> (raw)
In-Reply-To: <m3isrya6pk.fsf@uniton.integrable-solutions.net>


> | > 1) Shouldn't we pre-declare the function at global scope, then
> | >    do a using-declaration at the standard scope?
> |
> | The problem here is that they need to be treated as two independent
> | pre-declarations.  If a prototype or declaration is given for
> | one, it does not automatically anticipate/declare the other.  Hence,
> | we require separate DECLs with independent DECL_ANTICIPATED flags.
>
> Hmm, why do we need to have two independent declarations for the same
> builtin?

Because of the way that duplicate_decls overwrites the original
decl when redeclaring a declaration, such as when an anticipated
built-in function is prototyped.

If a single decl was shared between ::strlen and std::strlen, then
the destructive modification of the first decl would side-effect
the second.  I'd hoped this was clear from my reference to the
DECL_ANTICIPATED flag.  Setting it to true for the decl in the
first namespace should not automatically set the DECL_ANTICIPATED
field of the pre-declaration in the second namespace.


I believe/hope that the DECLs themselves take up very little space,
they don't contain any RTL, they share their types and other major
fields.  So the DECL itself just acts a place holder, associating
the namespace/identifier, with its types, flags and attributes.


> If we have the same builtin declared twice with possibly two
> incompatible declarations, it occurs to me that we're calling for
> trouble.  Is there any case where that could be useful?

The DECL_BUILT_IN and similar attributes are only preserved if
the declarations are compatible.  If the type of the redeclaration
doesn't match the anticipated/pre-declared type, the old decl is
just completely overwritten.

Consider:

// Global namespace declaration matches anticipated type.
extern "C" size_t strlen(const char *);

// std namespace declaration doesn't match anticipated type.
namespace std {
double strlen;
}

We end up modifying or overwritting the anticipated decls for each
redeclaration, but clearly with very different information in each.
Its not that we use the same "built-in" function with different
types, but that we may or may not completely overwrite the decls
based upon different types, i.e. redeclare the DECL associated with
the identifier differently in different contexts.  The built-in only
gets used when the types match.

A less ambiguous/confusing example might be:

int strlen;
namespace std { double strlen; }

in which neither declaration matches the pre-declared built-in.


> The point is that I have been reworking some part of th name lookup
> machinery, and that particular behaviour crashes the compiler until I
> realized that declarations (of builtins) in the outer space is no good.
> If they  are supposed to be pre-declared at the global scope (as the
> comment indicates), then their DECL_CONTEXT should point to
> global_namespace.  I'll make that change, once I understand the other
> issue.

That sounds very reasonable.  Fortunately, fixing this should be
independent of the first issue.  You can be forgiven for being confused
by the current convoluted scheme.  I'd really like to see reuse of
old DECLs in C/C++'s duplicate_decls removed, but the entire area is
a minefield, and the current implementation has the one redeeming
feature that, for the time being, it works and works efficiently.

I hope this is clearer with a second explanation.

Roger
--

  reply	other threads:[~2003-05-26  2:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-26  0:33 Roger Sayle
2003-05-26  2:08 ` Gabriel Dos Reis
2003-05-26  2:44   ` Roger Sayle [this message]
2003-05-26  4:26     ` Gabriel Dos Reis
  -- strict thread matches above, loose matches on Subject: below --
2003-05-25 22:13 gcc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0305251921330.5055-100000@www.eyesopen.com \
    --to=roger@eyesopen.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdr@integrable-solutions.net \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).