On Tue, Oct 21, 2014 at 7:52 PM, Richard Trieu <[email protected]> wrote:
> Author: rtrieu > Date: Tue Oct 21 21:52:00 2014 > New Revision: 220363 > > URL: http://llvm.org/viewvc/llvm-project?rev=220363&view=rev > Log: > 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. > > Modified: > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > cfe/trunk/test/SemaCXX/uninitialized.cpp > > Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=220363&r1=220362&r2=220363&view=diff > > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Oct 21 21:52:00 2014 > @@ -2525,6 +2525,9 @@ namespace { > > const CXXRecordDecl *RD = Constructor->getParent(); > > + if (RD->getDescribedClassTemplate() != nullptr) > + return; > + > Isn't the LLVM style to not explicitly check for nullptr? That is: if (!RD->getDescribedClassTemplate()) return; > // Holds fields that are uninitialized. > llvm::SmallPtrSet<ValueDecl*, 4> UninitializedFields; > > > Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=220363&r1=220362&r2=220363&view=diff > > ============================================================================== > --- cfe/trunk/test/SemaCXX/uninitialized.cpp (original) > +++ cfe/trunk/test/SemaCXX/uninitialized.cpp Tue Oct 21 21:52:00 2014 > @@ -1220,3 +1220,46 @@ namespace init_list { > {} > }; > } > + > +namespace template_class { > +class Foo { > + public: > + int *Create() { return nullptr; } > +}; > + > +template <typename T> > +class A { > +public: > + // Don't warn on foo here. > + A() : ptr(foo->Create()) {} > + > +private: > + Foo *foo = new Foo; > + int *ptr; > +}; > + > +template <typename T> > +class B { > +public: > + // foo is uninitialized here, but class B is never instantiated. > + B() : ptr(foo->Create()) {} > + > +private: > + Foo *foo; > + int *ptr; > +}; > + > +template <typename T> > +class C { > +public: > + C() : ptr(foo->Create()) {} > + // expected-warning@-1 {{field 'foo' is uninitialized when used here}} > +private: > + Foo *foo; > + int *ptr; > +}; > + > +C<int> c; > +// expected-note@-1 {{in instantiation of member function > 'template_class::C<int>::C' requested here}} > + > +} > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > -- Saleem Abdulrasool compnerd (at) compnerd (dot) org
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
