]> granicus.if.org Git - clang/commitdiff
Handle CXXOperatorCallExpr when checking self referrnce during initialization of
authorRichard Trieu <rtrieu@google.com>
Tue, 26 Mar 2013 03:41:40 +0000 (03:41 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 26 Mar 2013 03:41:40 +0000 (03:41 +0000)
class types.

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

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

index cb05bb0099e20fda4b302f208984f591486ba52c..9261df559e9b5f93fc28350a00defbf45a30d39c 100644 (file)
@@ -7097,6 +7097,14 @@ namespace {
       Visit(Base);
     }
 
+    void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+      if (E->getNumArgs() > 0)
+        if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->getArg(0)))
+          HandleDeclRefExpr(DRE);
+
+      Inherited::VisitCXXOperatorCallExpr(E);
+    }
+
     void VisitUnaryOperator(UnaryOperator *E) {
       // For POD record types, addresses of its own members are well-defined.
       if (E->getOpcode() == UO_AddrOf && isRecordType &&
index 3a41114e871d1afbdde16d4e20bd46ec12351925..2aa56623f6993177639c513fc9cda121f3a8f33e 100644 (file)
@@ -496,3 +496,18 @@ namespace references {
     int &b;
   };
 }
+
+namespace operators {
+  struct A {
+    A(bool);
+    bool operator==(A);
+  };
+
+  A makeA();
+
+  A a1 = a1 = makeA();  // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
+  A a2 = a2 == a1;  // expected-warning{{variable 'a2' is uninitialized when used within its own initialization}}
+  A a3 = a2 == a3;  // expected-warning{{variable 'a3' is uninitialized when used within its own initialization}}
+
+  int x = x = 5;
+}