From 277ace025d5afe04ebf059017d0cae985ca3c34d Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 22 Oct 2014 02:52:00 +0000 Subject: [PATCH] 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. llvm-svn: 220363 --- clang/lib/Sema/SemaDeclCXX.cpp | 3 +++ clang/test/SemaCXX/uninitialized.cpp | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 1d87abb..283f032 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp index 2596dd0..61dabb2 100644 --- a/clang/test/SemaCXX/uninitialized.cpp +++ b/clang/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}} + +} -- 2.7.4