Disable the uninitialized field warning in uninstantiated classes.
authorRichard Trieu <rtrieu@google.com>
Wed, 22 Oct 2014 02:52:00 +0000 (02:52 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 22 Oct 2014 02:52:00 +0000 (02:52 +0000)
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
clang/test/SemaCXX/uninitialized.cpp

index 1d87abb..283f032 100644 (file)
@@ -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;
 
index 2596dd0..61dabb2 100644 (file)
@@ -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}}
+
+}