[cfe-commits] r164366 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor-initializer.cpp test/SemaCXX/defaulted-ctor-loop.cpp test/SemaCXX/uninitialized.cpp

Hans Wennborg hans at hanshq.net
Fri Sep 21 01:58:33 PDT 2012


Author: hans
Date: Fri Sep 21 03:58:33 2012
New Revision: 164366

URL: http://llvm.org/viewvc/llvm-project?rev=164366&view=rev
Log:
Make warnings about uninitialized fields include the field name.

This makes the wording more informative, and consistent with the other
warnings about uninitialized variables.

Also, me and David who reviewed this couldn't figure out why we would
need to do a lookup to get the name of the variable; so just print the
name directly.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/constructor-initializer.cpp
    cfe/trunk/test/SemaCXX/defaulted-ctor-loop.cpp
    cfe/trunk/test/SemaCXX/uninitialized.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 21 03:58:33 2012
@@ -1210,10 +1210,10 @@
   "reference member of type %0 uninitialized">;
 def note_uninit_reference_member : Note<
   "uninitialized reference member is here">;
-def warn_field_is_uninit : Warning<"field is uninitialized when used here">,
+def warn_field_is_uninit : Warning<"field %0 is uninitialized when used here">,
   InGroup<Uninitialized>;
 def warn_reference_field_is_uninit : Warning<
-  "reference is not yet bound to a value when used here">,
+  "reference %0 is not yet bound to a value when used here">,
   InGroup<Uninitialized>;
 def warn_uninit_self_reference_in_init : Warning<
   "variable %0 is uninitialized when used within its own initialization">,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 21 03:58:33 2012
@@ -6328,14 +6328,12 @@
     void HandleDeclRefExpr(DeclRefExpr *DRE) {
       Decl* ReferenceDecl = DRE->getDecl(); 
       if (OrigDecl != ReferenceDecl) return;
-      LookupResult Result(S, DRE->getNameInfo(), Sema::LookupOrdinaryName,
-                          Sema::NotForRedeclaration);
       unsigned diag = isReferenceType
           ? diag::warn_uninit_self_reference_in_reference_init
           : diag::warn_uninit_self_reference_in_init;
       S.DiagRuntimeBehavior(DRE->getLocStart(), DRE,
                             S.PDiag(diag)
-                              << Result.getLookupName()
+                              << DRE->getNameInfo().getName()
                               << OrigDecl->getLocation()
                               << DRE->getSourceRange());
     }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Sep 21 03:58:33 2012
@@ -1717,7 +1717,7 @@
           unsigned diag = VD->getType()->isReferenceType()
               ? diag::warn_reference_field_is_uninit
               : diag::warn_field_is_uninit;
-          S.Diag(ME->getExprLoc(), diag);
+          S.Diag(ME->getExprLoc(), diag) << ME->getMemberNameInfo().getName();
           return;
         }
       }

Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Fri Sep 21 03:58:33 2012
@@ -135,12 +135,12 @@
   TwoInOne D;
   int E;
   InitializeUsingSelfTest(int F)
-      : A(A),  // expected-warning {{field is uninitialized when used here}}
-        B((((B)))),  // expected-warning {{field is uninitialized when used here}}
-        C(A && InitializeUsingSelfTest::C),  // expected-warning {{field is uninitialized when used here}}
-        D(D,  // expected-warning {{field is uninitialized when used here}}
-          D), // expected-warning {{field is uninitialized when used here}}
-        E(IntParam(E)) {} // expected-warning {{field is uninitialized when used here}}
+      : A(A),  // expected-warning {{field 'A' is uninitialized when used here}}
+        B((((B)))),  // expected-warning {{field 'B' is uninitialized when used here}}
+        C(A && InitializeUsingSelfTest::C),  // expected-warning {{field 'C' is uninitialized when used here}}
+        D(D,  // expected-warning {{field 'D' is uninitialized when used here}}
+          D), // expected-warning {{field 'D' is uninitialized when used here}}
+        E(IntParam(E)) {} // expected-warning {{field 'E' is uninitialized when used here}}
 };
 
 int IntWrapper(int &i) { return 0; };
@@ -160,8 +160,8 @@
   bool A, B, C;
   CopyConstructorTest(const CopyConstructorTest& rhs)
       : A(rhs.A),
-        B(B),  // expected-warning {{field is uninitialized when used here}}
-        C(rhs.C || C) { }  // expected-warning {{field is uninitialized when used here}}
+        B(B),  // expected-warning {{field 'B' is uninitialized when used here}}
+        C(rhs.C || C) { }  // expected-warning {{field 'C' is uninitialized when used here}}
 };
 
 // Make sure we aren't marking default constructors when we shouldn't be.

Modified: cfe/trunk/test/SemaCXX/defaulted-ctor-loop.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/defaulted-ctor-loop.cpp?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/defaulted-ctor-loop.cpp (original)
+++ cfe/trunk/test/SemaCXX/defaulted-ctor-loop.cpp Fri Sep 21 03:58:33 2012
@@ -9,6 +9,6 @@
 struct foo {
   bar b;
   foo()
-    : b(b) // expected-warning{{field is uninitialized}}
+    : b(b) // expected-warning{{field 'b' is uninitialized}}
   {}
 };

Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=164366&r1=164365&r2=164366&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Fri Sep 21 03:58:33 2012
@@ -173,11 +173,11 @@
   int x;
   void *ptr;
 
-  S(bool (*)[1]) : x(x) {} // expected-warning {{field is uninitialized when used here}}
-  S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field is uninitialized when used here}}
-  S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field is uninitialized when used here}}
-  S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field is uninitialized when used here}}
-  S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field is uninitialized when used here}}
+  S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}}
+  S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
+  S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field 'x' is uninitialized when used here}}
+  S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
+  S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
 
   // These don't actually require the value of x and so shouldn't warn.
   S(char (*)[1]) : x(sizeof(x)) {} // rdar://8610363
@@ -262,8 +262,8 @@
     C c;
     D(char (*)[1]) : c(c.b.a.A1) {}
     D(char (*)[2]) : c(c.b.a.A2()) {}
-    D(char (*)[3]) : c(c.b.a.A3) {}    // expected-warning {{field is uninitialized when used here}}
-    D(char (*)[4]) : c(c.b.a.A4()) {}  // expected-warning {{field is uninitialized when used here}}
+    D(char (*)[3]) : c(c.b.a.A3) {}    // expected-warning {{field 'c' is uninitialized when used here}}
+    D(char (*)[4]) : c(c.b.a.A4()) {}  // expected-warning {{field 'c' is uninitialized when used here}}
 
     // c::a is static, so it is already initialized
     D(char (*)[5]) : c(c.a.A1) {}
@@ -274,21 +274,21 @@
 
   struct E {
     int a, b, c;
-    E(char (*)[1]) : a(a ? b : c) {}  // expected-warning {{field is uninitialized when used here}}
-    E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field is uninitialized when used here}}
-    E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field is uninitialized when used here}}
-    E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field is uninitialized when used here}}
+    E(char (*)[1]) : a(a ? b : c) {}  // expected-warning {{field 'a' is uninitialized when used here}}
+    E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
+    E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field 'a' is uninitialized when used here}}
+    E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field 'a' is uninitialized when used here}}
     E(char (*)[5]) : a(b ? c : b) {}
 
-    E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field is uninitialized when used here}}
-    E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field is uninitialized when used here}}
-    E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field is uninitialized when used here}}
+    E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
+    E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}}
+    E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field 'a' is uninitialized when used here}}
     E(char (*)[9]) : a(b ?: c) {}
 
     E(char (*)[10]) : a((a, a, b)) {}
-    E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field is uninitialized when used here}}
-    E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field is uninitialized when used here}}
-    E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field is uninitialized when used here}}
+    E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
+    E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
+    E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
     E(char (*)[14]) : a((b, c, c)) {}
   };
 
@@ -304,16 +304,16 @@
   struct G {
     F f1, f2;
     F *f3, *f4;
-    G(char (*)[1]) : f1(f1) {} // expected-warning {{field is uninitialized when used here}}
+    G(char (*)[1]) : f1(f1) {} // expected-warning {{field 'f1' is uninitialized when used here}}
     G(char (*)[2]) : f2(f1) {}
     G(char (*)[3]) : f2(F()) {}
 
-    G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field is uninitialized when used here}}
+    G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field 'f1' is uninitialized when used here}}
     G(char (*)[5]) : f2(f1.*ptr) {}
 
-    G(char (*)[6]) : f3(f3) {}  // expected-warning {{field is uninitialized when used here}}
-    G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field is uninitialized when used here}}
-    G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field is uninitialized when used here}}
+    G(char (*)[6]) : f3(f3) {}  // expected-warning {{field 'f3' is uninitialized when used here}}
+    G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field 'f3' is uninitialized when used here}}
+    G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field 'f3' is uninitialized when used here}}
   };
 }
 
@@ -381,7 +381,7 @@
 
 namespace in_class_initializers {
   struct S {
-    S() : a(a + 1) {} // expected-warning{{field is uninitialized when used here}}
+    S() : a(a + 1) {} // expected-warning{{field 'a' is uninitialized when used here}}
     int a = 42; // Note: because a is in a member initializer list, this initialization is ignored.
   };
 
@@ -402,7 +402,7 @@
   int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
 
   struct S {
-    S() : a(a) {} // expected-warning{{reference is not yet bound to a value when used here}}
+    S() : a(a) {} // expected-warning{{reference 'a' is not yet bound to a value when used here}}
     int &a;
   };
 
@@ -413,7 +413,7 @@
   struct T {
     T() : a(b), b(a) {} // FIXME: Warn here.
     int &a, &b;
-    int &c = c; // expected-warning{{reference is not yet bound to a value when used here}}
+    int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}}
   };
 
   int x;





More information about the cfe-commits mailing list