From: Douglas Gregor Date: Tue, 27 Apr 2010 16:20:13 +0000 (+0000) Subject: Don't look into incomplete types when trying to warn about unused X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6a292b4dc47da42b2fc0662af7fe278c9e9fb33;p=clang Don't look into incomplete types when trying to warn about unused variables. Fixes PR6948. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102436 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 3f309bb6ad..d9696d9ed5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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()) { const TagDecl *Tag = TT->getDecl(); if (Tag->hasAttr()) diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 3b5349a5ce..5ef7e7002f 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -51,3 +51,11 @@ void test_dependent_init(T *p) { X0 i(p); (void)i; } + +namespace PR6948 { + template class X; + + void f() { + X str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} + } +}