[cfe-commits] r171240 - in /cfe/trunk: lib/Sema/Sema.cpp test/SemaCXX/undefined-internal.cpp

Rafael Espindola rafael.espindola at gmail.com
Sat Dec 29 15:43:00 PST 2012


Author: rafael
Date: Sat Dec 29 17:43:00 2012
New Revision: 171240

URL: http://llvm.org/viewvc/llvm-project?rev=171240&view=rev
Log:
Don't warn for undefined but used decls that are external because of a typedef.

This fixes pr14736. It is fairly ugly, but I don't think we can do much better
as we have to wait at least until the end of the typedef to know if the
function will have external linkage or not.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/SemaCXX/undefined-internal.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=171240&r1=171239&r2=171240&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Dec 29 17:43:00 2012
@@ -394,6 +394,9 @@
     // Ignore attributes that have become invalid.
     if (decl->isInvalidDecl()) continue;
 
+    // If we found out that the decl is external, don't warn.
+    if (decl->getLinkage() == ExternalLinkage) continue;
+
     // __attribute__((weakref)) is basically a definition.
     if (decl->hasAttr<WeakRefAttr>()) continue;
 

Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=171240&r1=171239&r2=171240&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Sat Dec 29 17:43:00 2012
@@ -181,3 +181,21 @@
   template<void x(int)> void t(long*) { x(10); } // expected-note {{used here}}
   void g() { long a; t<f>(&a); }
 }
+
+namespace test7 {
+  typedef struct {
+    void bar();
+    void foo() {
+      bar();
+    }
+  } A;
+}
+
+namespace test8 {
+  typedef struct {
+    void bar(); // expected-warning {{function 'test8::<anonymous struct>::bar' has internal linkage but is not defined}}
+    void foo() {
+      bar(); // expected-note {{used here}}
+    }
+  } *A;
+}





More information about the cfe-commits mailing list