[cfe-dev] [Patch] AST support, and unqualified name lookup for using-directives

Douglas Gregor dgregor at apple.com
Tue Feb 3 11:27:02 PST 2009


On Feb 3, 2009, at 11:24 AM, Douglas Gregor wrote:
> One thing I noticed about ActOnTag:
>
> @@ -2824,8 +2826,20 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S,  
> unsigned TagSpec, TagKind TK,
>    } else if (Name) {
>      // If this is a named struct, check to see if there was a  
> previous forward
>      // declaration or definition.
> -    Decl *D = LookupName(S, Name, LookupTagName);
> -    PrevDecl = dyn_cast_or_null<NamedDecl>(D);
> +    LookupResult R = LookupName(S, Name, LookupTagName);
> +    if (R.isAmbiguous()) {
> +      DiagnoseAmbiguousLookup(R, Name, NameLoc);
> +      // FIXME: This is not best way to recover from case like:
> +      //
> +      // struct S s;
> +      //
> +      // causes needless err_ovl_no_viable_function_in_init latter.
> +      Name = 0;
> +      PrevDecl = 0;
> +      Invalid = true;
> +    }
> +    else
> +      PrevDecl = dyn_cast_or_null<NamedDecl>(static_cast<Decl*>(R));
>
>      if (!getLangOptions().CPlusPlus && TK != TK_Reference) {
>        // FIXME: This makes sure that we ignore the contexts  
> associated
>
> This is going to diagnose ambiguities even when we shouldn't  
> because, for example, we might be declaring a class or enum type in  
> a new scope, but LookupName is finding something ambiguous in a  
> different (parent) scope. I added two test cases here, one involving  
> using-directives and one involving base-class lookup, that trigger  
> the bug.
>
> However, I think it's best if I tackle this one. I've been doing a  
> bit of work in ActOnTag recently, and I have both the C and C++  
> rules fresh in my mind.


Well, that was easy. This issue is now fixed (and ActOnTag will be a  
bit faster in C++).

	- Doug



More information about the cfe-dev mailing list