[cfe-dev] PATCH: Cleanup function redeclaration representations

Doug Gregor doug.gregor at gmail.com
Thu May 1 18:57:33 PDT 2008


Chris - there's a patch in here that you probably want to take a look at.

On Fri, Apr 25, 2008 at 4:42 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Doug Gregor wrote:
>  How about
>
>  (1) -#2 is checked for error diagnostics by considering default args from
> both #1 and #2
>
>
>  And in the end, only #1 gets the merged args. This is the same as only #2
> gets the merged args.

I went a slightly different way... both #1 and #2 get the merged args
(so each shows the complete state at that time), but we use
CXXDefauiltArgExpr for default arguments that were the result of
merging default arguments. That way, we always know exactly which
parameter (in which declaration) the default argument originally came
from.

>  Actually, I'm thinking that maybe there could be a common convention that,
> not only functions, but vars and namespaces should follow.
>  An extended namespace definition could be regarded as a redeclaration.

Yes, agreed. I've moved addRedeclaration (and its brethren) into
ScopedDecl, so the same approach can apply to extern variables,
functions, namespaces, classes, etc.

>  I agree that it is philosophical, thus I don't really care much about the
> name pointing to the first or the last decl.
>  What bothers me is the "swapping content" bit. It seems to me that feeding
> to the consumer the same pointer for, essentially, different
>  declaration objects is a source of complexity and possible subtle bugs,
> without much benefit.

I was never quite thrilled with the swapping bit, either.

>  I hope I'm not coming off as too pedantic :)

It's a C++ front end, so it pays to be pedantic.

Anyway, you've convinced me. The attached patch makes a few changes to
the way redeclarations are handled:

  1) The swapping behavior is gone; instead, we merge into the
redeclaration and into the original declaration.
  2) The addRedeclaration/getNextRedeclaration function has moved into
ScopedDecl, so it can be used for other kinds of declarations
  3) We use a DenseMap to store the redeclaration links, since so few
actual ScopedDecls will have redeclarations
  4) We keep track of where merged default arguments came from, so
that we can provide better diagnostics for them.


  - Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-redecl-noswap.patch
Type: text/x-patch
Size: 15024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080501/e6e46b3b/attachment.bin>


More information about the cfe-dev mailing list