]> granicus.if.org Git - clang/commitdiff
When checking for uninitialized fields in member initializers, special case static...
authorAnders Carlsson <andersca@mac.com>
Wed, 6 Oct 2010 02:43:25 +0000 (02:43 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 6 Oct 2010 02:43:25 +0000 (02:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/constructor-initializer.cpp

index 1e4065454ed827228bd3bfb8e6686d1c965db459..cbb16fe17ed0788c0d8700401bfe51f0c38ae5a3 100644 (file)
@@ -1163,6 +1163,19 @@ static bool InitExprContainsUninitializedFields(const Stmt *S,
   }
   if (const MemberExpr *ME = dyn_cast<MemberExpr>(S)) {
     const NamedDecl *RhsField = ME->getMemberDecl();
+
+    if (const VarDecl *VD = dyn_cast<VarDecl>(RhsField)) {
+      // The member expression points to a static data member.
+      assert(VD->isStaticDataMember() && 
+             "Member points to non-static data member!");
+      return false;
+    }
+    
+    if (isa<EnumConstantDecl>(RhsField)) {
+      // The member expression points to an enum.
+      return false;
+    }
+
     if (RhsField == LhsField) {
       // Initializing a field with itself. Throw a warning.
       // But wait; there are exceptions!
index a74fbe1800e2c04442c4e4124721046c2ef4c8a7..e439a76c17cc357f6fb5c504feb41ef70cae8a0e 100644 (file)
@@ -239,3 +239,32 @@ namespace test3 {
     }
   };
 }
+
+// PR8075
+namespace PR8075 {
+
+struct S1 {
+  enum { FOO = 42 };
+  static const int bar = 42;
+  static int baz();
+  S1(int);
+};
+
+const int S1::bar;
+
+struct S2 {
+  S1 s1;
+  S2() : s1(s1.FOO) {}
+};
+
+struct S3 {
+  S1 s1;
+  S3() : s1(s1.bar) {}
+};
+
+struct S4 {
+  S1 s1;
+  S4() : s1(s1.baz()) {}
+};
+
+}