]> granicus.if.org Git - clang/commitdiff
Don't look into incomplete types when trying to warn about unused
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 16:20:13 +0000 (16:20 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 16:20:13 +0000 (16:20 +0000)
variables. Fixes PR6948.

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

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unused-variables.cpp

index 3f309bb6adaafb2ee62c217dd92315edf008443e..d9696d9ed596d086cdec7e6e9296e34a0181945d 100644 (file)
@@ -543,6 +543,11 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
         return false;
     }
 
+    // If we failed to complete the type for some reason, don't
+    // diagnose the variable.
+    if (Ty->isIncompleteType())
+      return false;
+
     if (const TagType *TT = Ty->getAs<TagType>()) {
       const TagDecl *Tag = TT->getDecl();
       if (Tag->hasAttr<UnusedAttr>())
index 3b5349a5ce1bf5c08af9d1731b29d2a64587bfe6..5ef7e7002f65abbd10720f996a3a71c841258032 100644 (file)
@@ -51,3 +51,11 @@ void test_dependent_init(T *p) {
   X0<int> i(p);
   (void)i;
 }
+
+namespace PR6948 {
+  template<typename T> class X;
+  
+  void f() {
+    X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
+  }
+}