Enable -Wunreachable-code and fix duplicate warning flags

llvm-svn: 290486
diff --git a/libcxx/test/libcxx/compiler.py b/libcxx/test/libcxx/compiler.py
index de716ec..8585f44 100644
--- a/libcxx/test/libcxx/compiler.py
+++ b/libcxx/test/libcxx/compiler.py
@@ -147,9 +147,6 @@
         cmd += flags
         return cmd
 
-    def _getWarningFlags(self):
-        return self.warning_flags if self.use_warnings else []
-
     def preprocessCmd(self, source_files, out=None, flags=[]):
         return self._basicCmd(source_files, out, flags=flags,
                              mode=self.CM_PreProcess,
@@ -277,22 +274,21 @@
         another error is triggered during compilation.
         """
         assert isinstance(flag, str)
+        assert flag.startswith('-W')
         if not flag.startswith('-Wno-'):
-            if self.hasCompileFlag(flag):
-                self.warning_flags += [flag]
-                return True
-            return False
+            return self.hasCompileFlag(flag)
         flags = ['-Werror', flag]
         old_use_warnings = self.use_warnings
         self.useWarnings(False)
         cmd = self.compileCmd('-', os.devnull, flags)
-        self.useWarnings(True)
+        self.useWarnings(old_use_warnings)
         # Remove '-v' because it will cause the command line invocation
         # to be printed as part of the error output.
         # TODO(EricWF): Are there other flags we need to worry about?
         if '-v' in cmd:
             cmd.remove('-v')
         out, err, rc = lit.util.executeCommand(cmd, input='#error\n')
+
         assert rc != 0
         if flag in err:
             return False
@@ -300,6 +296,7 @@
 
     def addWarningFlagIfSupported(self, flag):
         if self.hasWarningFlag(flag):
+            assert flag not in self.warning_flags
             self.warning_flags += [flag]
             return True
         return False
diff --git a/libcxx/test/libcxx/test/config.py b/libcxx/test/libcxx/test/config.py
index 250c2f1..c240868 100644
--- a/libcxx/test/libcxx/test/config.py
+++ b/libcxx/test/libcxx/test/config.py
@@ -646,6 +646,7 @@
         enable_warnings = self.get_lit_bool('enable_warnings',
                                             default_enable_warnings)
         if enable_warnings:
+            self.cxx.useWarnings(True)
             self.cxx.warning_flags += [
                 '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
                 '-Wall', '-Wextra', '-Werror'
@@ -662,6 +663,7 @@
             self.cxx.addWarningFlagIfSupported('-Wsign-compare')
             self.cxx.addWarningFlagIfSupported('-Wunused-variable')
             self.cxx.addWarningFlagIfSupported('-Wunused-parameter')
+            self.cxx.addWarningFlagIfSupported('-Wunreachable-code')
             # FIXME: Enable the two warnings below.
             self.cxx.addWarningFlagIfSupported('-Wno-conversion')
             self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
diff --git a/libcxx/test/std/thread/futures/futures.async/async.pass.cpp b/libcxx/test/std/thread/futures/futures.async/async.pass.cpp
index 0f5ee05..9adebb2 100644
--- a/libcxx/test/std/thread/futures/futures.async/async.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/async.pass.cpp
@@ -72,7 +72,8 @@
 void f5(int j)
 {
     std::this_thread::sleep_for(ms(200));
-    TEST_THROW(j); ((void)j);
+    ((void)j);
+    TEST_THROW(j);
 }
 
 template <class Ret, class CheckLamdba, class ...Args>