r220363 - Disable the uninitialized field warning in uninstantiated classes.

Richard Trieu rtrieu at google.com
Tue Oct 21 19:52:00 PDT 2014


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;
+
     // 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 at -1 {{field 'foo' is uninitialized when used here}}
+private:
+  Foo *foo;
+  int *ptr;
+};
+
+C<int> c;
+// expected-note at -1 {{in instantiation of member function 'template_class::C<int>::C' requested here}}
+
+}





More information about the cfe-commits mailing list