]> granicus.if.org Git - clang/commitdiff
Better wording for reference self-initialization warning.
authorHans Wennborg <hans@hanshq.net>
Mon, 20 Aug 2012 08:52:22 +0000 (08:52 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 20 Aug 2012 08:52:22 +0000 (08:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162198 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
test/Analysis/stack-addr-ps.cpp
test/SemaCXX/references.cpp
test/SemaCXX/uninitialized.cpp

index 0623966279657c034eb0e6c9542e44edda7be8d8..065b5b1bed745fe3d419bb704ede724d455de33c 100644 (file)
@@ -1216,9 +1216,16 @@ def note_uninit_reference_member : Note<
   "uninitialized reference member is here">;
 def warn_field_is_uninit : Warning<"field 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">,
+  InGroup<Uninitialized>;
 def warn_uninit_self_reference_in_init : Warning<
   "variable %0 is uninitialized when used within its own initialization">,
   InGroup<Uninitialized>;
+def warn_uninit_self_reference_in_reference_init : Warning<
+  "reference %0 is not yet bound to a value when used within its own"
+  " initialization">,
+  InGroup<Uninitialized>;
 def warn_uninit_var : Warning<
   "variable %0 is uninitialized when %select{used here|captured by block}1">,
   InGroup<Uninitialized>, DefaultIgnore;
index 84ddf36ecc7682d2bc31df02a85d12ff77affd63..cd6a60b47b7401e5b2abe6da3df7d32bc8c32fb0 100644 (file)
@@ -6275,8 +6275,11 @@ namespace {
       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::warn_uninit_self_reference_in_init)
+                            S.PDiag(diag)
                               << Result.getLookupName()
                               << OrigDecl->getLocation()
                               << DRE->getSourceRange());
index eeac9b8e8d70709e4f6a27a898c268fca52e6f05..2d3f2c023962b1024292ed96e373e8daa86097d9 100644 (file)
@@ -2080,7 +2080,10 @@ namespace {
         }
 
         if (VD == ME->getMemberDecl() && isa<CXXThisExpr>(Base)) {
-          S.Diag(ME->getExprLoc(), diag::warn_field_is_uninit);
+          unsigned diag = VD->getType()->isReferenceType()
+              ? diag::warn_reference_field_is_uninit
+              : diag::warn_field_is_uninit;
+          S.Diag(ME->getExprLoc(), diag);
           return;
         }
       }
index cbdb143c1857e0d02d9360c9d0b867f4e270dddf..a27bef793c47a862844176d73e7cc242aa40e445 100644 (file)
@@ -87,6 +87,6 @@ struct TS {
 
 // rdar://11345441
 int* f5() {
-  int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}} expected-warning{{variable 'i' is uninitialized when used within its own initialization}}
+  int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}} expected-warning{{reference 'i' is not yet bound to a value when used within its own initialization}}
   return &i; // expected-warning {{address of stack memory associated with local variable 'i' returned}}
 }
index 028c6909210ec1129fb9b97a98dd5625d5b80d86..4f3dab0514b9d1ea6facc117838c52b89430b1fa 100644 (file)
@@ -136,4 +136,4 @@ namespace PR8608 {
 }
 
 // The following crashed trying to recursively evaluate the LValue.
-const int &do_not_crash = do_not_crash; // expected-warning{{variable 'do_not_crash' is uninitialized when used within its own initialization}}
+const int &do_not_crash = do_not_crash; // expected-warning{{reference 'do_not_crash' is not yet bound to a value when used within its own initialization}}
index 385548b51cca63f6554d42ad1c836432a9bf7c6b..0633764c1b44e8cc29678d562bf6ee1c79964275 100644 (file)
@@ -380,15 +380,15 @@ namespace statics {
 }
 
 namespace references {
-  int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
+  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{{field is uninitialized when used here}}
+    S() : a(a) {} // expected-warning{{reference is not yet bound to a value when used here}}
     int &a;
   };
 
   void f() {
-    int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
+    int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
   }
 
   struct T {