Make the selection of type declarations in Sema::getTypeName
authorDouglas Gregor <dgregor@apple.com>
Mon, 13 Apr 2009 15:14:38 +0000 (15:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 13 Apr 2009 15:14:38 +0000 (15:14 +0000)
deterministic when faced with an ambiguity. This eliminates the
annoying test/SemaCXX/using-directive.cpp failure.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68952 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/using-directive.cpp

index 7d276178916dbea07579f7e81d7b3eae97bf2d64..018f74816a408d1b2114bd4d820195ebdaa3da14 100644 (file)
@@ -85,8 +85,10 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
     for (LookupResult::iterator Res = Result.begin(), ResEnd = Result.end();
          Res != ResEnd; ++Res) {
       if (isa<TypeDecl>(*Res) || isa<ObjCInterfaceDecl>(*Res)) {
-        IIDecl = *Res;
-        break;
+        if (!IIDecl || 
+            (*Res)->getLocation().getRawEncoding() < 
+              IIDecl->getLocation().getRawEncoding())
+          IIDecl = *Res;
       }
     }
 
index a4d35c4802c7d6c8f4c711b20d6dc5549db54b9c..924cf077b63f01f144d1e1b29a672b7360454f24 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-// XFAIL
 
 namespace A {
   short i; // expected-note 2{{candidate found by name lookup is 'A::i'}}
@@ -95,8 +94,7 @@ namespace OneFunction {
 }
 
 namespace TwoTag {
-  struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}} \
-  // expected-note{{forward declaration}}
+  struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}}
 }
 
 namespace FuncHidesTagAmbiguity {
@@ -105,7 +103,6 @@ namespace FuncHidesTagAmbiguity {
   using namespace TwoTag;
 
   void test() {
-    (void)X(); // expected-error{{reference to 'X' is ambiguous}} \
-      // FIXME: expected-error{{invalid use of incomplete type}}
+    (void)X(); // expected-error{{reference to 'X' is ambiguous}}
   }
 }