[C++ Patch] PR 27211

Mark Mitchell mark@codesourcery.com
Tue Aug 14 21:29:00 GMT 2007


Paolo Carlini wrote:

> the idea for the fix is very simple: check_classfn currently returns
> NULL_TREE both in case of real error and when a declaration is just not
> found, per the comment at the beginning of its body. Telling those two
> situations apart fixes the PR.

The part of your patch that you didn't 'fess up to :-) is this bit:

-   /* If we did not find the method in the class, add it to avoid
-      spurious errors (unless the CTYPE is not yet defined, in which
-      case we'll only confuse ourselves when the function is declared
-      properly within the class.  */
-   if (COMPLETE_TYPE_P (ctype))
-     add_method (ctype, function, NULL_TREE);

That code was trying to handle this kind of thing:

  struct S {
  };

  void S::foo() { ... }

  void g() { S s; s.foo(); } // Avoid "spurious" error here.

However, I've always found the idea of stuffing methods into the class
after the fact unattractive.  It might help with error recovery, but it
goes against the core principle that we should try to keep the internal
representation valid and internally consistent.  For example, we've
already determined vtables and overriders by the point of hitting S::foo
above, and I bet we're not magically updating all of that.

So, I'm OK with this change; I just wanted to explicitly admit that we
were doing it.

The patch is OK, thanks.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list