Fix -Wunused-value to not warn on expressions that have unresolved lookups due
authorMatt Beaumont-Gay <matthewbg@google.com>
Tue, 23 Oct 2012 06:15:26 +0000 (06:15 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Tue, 23 Oct 2012 06:15:26 +0000 (06:15 +0000)
to dependent arguments.

llvm-svn: 166468

clang/lib/AST/Expr.cpp
clang/test/SemaCXX/unused.cpp

index 694325af22d7f0027dfe30caf44bd1cd9ab62ffc..3c8cbb56a0252f03be5f20a60f290a0eba0acb52 100644 (file)
@@ -1950,6 +1950,11 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
     return false;
   }
 
+  // If we don't know precisely what we're looking at, let's not warn.
+  case UnresolvedLookupExprClass:
+  case CXXUnresolvedConstructExprClass:
+    return false;
+
   case CXXTemporaryObjectExprClass:
   case CXXConstructExprClass:
     return false;
index b9877a1ba4f4b7214063bfa8fba35f38a5e07eb6..fbaf8c8bf3c124874408b93e75ac6b9ff4d99cbe 100644 (file)
@@ -46,3 +46,18 @@ namespace AnonObject {
     int(1); // expected-warning {{expression result unused}}
   }
 }
+
+// Test that constructing an object (which may have side effects) with
+// constructor arguments which are dependent doesn't produce an unused value
+// warning.
+namespace UnresolvedLookup {
+  struct Foo {
+    Foo(int i, int j);
+  };
+  template <typename T>
+  struct Bar {
+    void f(T t) {
+      Foo(t, 0);  // no warning
+    }
+  };
+}