]> granicus.if.org Git - clang/commitdiff
Fix -Wuninitialized to catch the case of a class being initialized with a call
authorRichard Trieu <rtrieu@google.com>
Thu, 8 Mar 2012 01:15:31 +0000 (01:15 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 8 Mar 2012 01:15:31 +0000 (01:15 +0000)
to its own member function.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152276 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/uninitialized.cpp

index 7a0ae94739e3dc34968b891aed28e8ec9006973b..33656c9d52d5ea9ee566dc75abf1a90b3cd14303 100644 (file)
@@ -5993,7 +5993,8 @@ namespace {
 
     void VisitMemberExpr(MemberExpr *E) {
       if (E->getType()->canDecayToPointerType()) return;
-      if (isa<FieldDecl>(E->getMemberDecl()))
+      ValueDecl *VD = E->getMemberDecl();
+      if (isa<FieldDecl>(VD) || isa<CXXMethodDecl>(VD))
         if (DeclRefExpr *DRE
               = dyn_cast<DeclRefExpr>(E->getBase()->IgnoreParenImpCasts())) {
           HandleDeclRefExpr(DRE);
index ec037cbb781814f4a89de1d9549fade0e821745d..955068291806161d6944dbc258b4378a1f7cc5b5 100644 (file)
@@ -33,6 +33,7 @@ class A {
     int num;
     static int count;
     int get() const { return num; }
+    int get2() { return num; }
     void set(int x) { num = x; }
     static int zero() { return 0; }
 
@@ -67,6 +68,7 @@ void setupA() {
   A a14 = A(a14);  // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
   A a15 = getA(a15.num);  // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
   A a16(&a16.num);  // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
+  A a17(a17.get2());  // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
 }
 
 struct B {