From: Richard Trieu Date: Wed, 22 Oct 2014 02:52:00 +0000 (+0000) Subject: Disable the uninitialized field warning in uninstantiated classes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25c85cacbdb06113e0b6411a285201bd65f7b6a2;p=clang Disable the uninitialized field warning in uninstantiated classes. If a templated class is not instantiated, then the AST for it could be missing some things that would throw the field checker off. Wait until specialization before emitting these warnings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220363 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 1d87abb33f..283f032061 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2525,6 +2525,9 @@ namespace { const CXXRecordDecl *RD = Constructor->getParent(); + if (RD->getDescribedClassTemplate() != nullptr) + return; + // Holds fields that are uninitialized. llvm::SmallPtrSet UninitializedFields; diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index 2596dd044d..61dabb2d00 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -1220,3 +1220,46 @@ namespace init_list { {} }; } + +namespace template_class { +class Foo { + public: + int *Create() { return nullptr; } +}; + +template +class A { +public: + // Don't warn on foo here. + A() : ptr(foo->Create()) {} + +private: + Foo *foo = new Foo; + int *ptr; +}; + +template +class B { +public: + // foo is uninitialized here, but class B is never instantiated. + B() : ptr(foo->Create()) {} + +private: + Foo *foo; + int *ptr; +}; + +template +class C { +public: + C() : ptr(foo->Create()) {} + // expected-warning@-1 {{field 'foo' is uninitialized when used here}} +private: + Foo *foo; + int *ptr; +}; + +C c; +// expected-note@-1 {{in instantiation of member function 'template_class::C::C' requested here}} + +}