Enable additional build warnings on Unix (dotnet/core-setup#6071)
authorOmair Majid <omajid@redhat.com>
Tue, 30 Apr 2019 18:03:58 +0000 (14:03 -0400)
committerVitek Karas <vitek.karas@microsoft.com>
Tue, 30 Apr 2019 18:03:57 +0000 (11:03 -0700)
* Enable -Wall, -Wextra, -Weverything and -Werror on Unix

This enables *all* native code warnings on gcc/clang.

To avoid breaking the build, this commit also explicitly disables all
warnings that currently cause the build to fail.

* Remove -Wno-zero-as-null-pointer-constant

Fix all the code that was causing the warnings.

* Fix newline-eof warnings

* Fix 'deprecated' warnings

Use `noexcept` instead of `throw()`.

Use explicit copy-constructors where the compiler complains.

* Fix non-virtual-destructor warnings

Add a virtual destructor

* Fix extra-semi warnings

* Fix some sign-compare warnings

But leave sign-compare warnings disabled: some shared API essentially
forces some code do this comparison.

* Fix ignored-qualifiers warnings

It doesn't matter when functions that return value types use const or
not: value types are returned by copying and the caller can't mutate the
the version that the callee had. So remove those const flags.

* Fix undef warnings

Use defined() for preprocessor flags that can be undefined.

* Fix range-loop-analysis warnings

* Enable shorten-64-to-32 warnings

Previous commits have fixed all code that produced this warning.

* Fix used-but-marked-unused warnings

* Fix missing-braces warnings

* Disable vla-extension warnings

* Fix missing-variable-declarations warnings

Fix the warnings by explicitly declaring the global variables that are
only meant to be used locally in the file as static.

* Enable sign-conversion warnings

The code seems to have been fixed by previous commits.

* Fix old-style-cast warnings

* Fix unused-variable warnings

* Fix sign-compare warnings

* Fix documentation-unknown-command warnings

Clang thinks these comment blocks enclosed by /** and **/ are
doxygen-style comments. And doxygen doesn't know of a \Program tag. Use
\\ to "escape" a single slash and make doxygen/clang happy.

* Disable -Weverything

And remove various -Wno- flags that are not required anymore.

* Update global locations that comments refer to

The original locations are basically wrong.

* Fix bad cast in mockcoreclr.cpp

We should set the left hand value (a host_handle_t) to a right hand
value of the same type (a host_handle_t). Casting `0xdeadbeef` to a
host_handle_t* - only to assign it to a host_handle_t - does't make too
much sense.

Commit migrated from https://github.com/dotnet/core-setup/commit/0dd08fe1414c690d3243739f3be4cd35f84f7dde

41 files changed:
src/installer/corehost/cli/apphost/bundle/bundle_runner.cpp
src/installer/corehost/cli/apphost/bundle/file_entry.cpp
src/installer/corehost/cli/deps_entry.cpp
src/installer/corehost/cli/deps_format.cpp
src/installer/corehost/cli/fx_reference.h
src/installer/corehost/cli/fxr/corehost_init.h
src/installer/corehost/cli/fxr/fx_muxer.cpp
src/installer/corehost/cli/fxr/fx_resolver.cpp
src/installer/corehost/cli/fxr/fx_resolver.h
src/installer/corehost/cli/fxr/hostfxr.cpp
src/installer/corehost/cli/fxr/hostpolicy_resolver.cpp
src/installer/corehost/cli/fxr_resolver.cpp
src/installer/corehost/cli/fxr_resolver.h
src/installer/corehost/cli/host_startup_info.cpp
src/installer/corehost/cli/host_startup_info.h
src/installer/corehost/cli/hostpolicy/args.cpp
src/installer/corehost/cli/hostpolicy/coreclr.cpp
src/installer/corehost/cli/hostpolicy/deps_resolver.cpp
src/installer/corehost/cli/hostpolicy/deps_resolver.h
src/installer/corehost/cli/hostpolicy/hostpolicy.cpp
src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp
src/installer/corehost/cli/hostpolicy/hostpolicy_init.cpp
src/installer/corehost/cli/json/casablanca/include/cpprest/asyncrt_utils.h
src/installer/corehost/cli/json/casablanca/include/cpprest/details/SafeInt3.hpp
src/installer/corehost/cli/json/casablanca/include/cpprest/details/nosal.h
src/installer/corehost/cli/json/casablanca/include/cpprest/json.h
src/installer/corehost/cli/json/casablanca/src/json/json_parsing.cpp
src/installer/corehost/cli/json/casablanca/src/utilities/asyncrt_utils.cpp
src/installer/corehost/cli/nethost/nethost.cpp
src/installer/corehost/cli/nethost/nethost.h
src/installer/corehost/cli/runtime_config.cpp
src/installer/corehost/cli/test/mockcoreclr/mockcoreclr.cpp
src/installer/corehost/cli/test/mockhostpolicy/mockhostpolicy.cpp
src/installer/corehost/cli/test/nativehost/comhost_test.h
src/installer/corehost/cli/test/nativehost/nativehost.cpp
src/installer/corehost/cli/version.h
src/installer/corehost/common/pal.unix.cpp
src/installer/corehost/common/trace.cpp
src/installer/corehost/common/utils.cpp
src/installer/corehost/corehost.cpp
src/installer/settings.cmake

index 3b6f8b3..c7e572a 100644 (file)
@@ -84,7 +84,7 @@ void bundle_runner_t::read_string(pal::string_t &str, size_t size, FILE* stream)
     uint8_t *buffer = new uint8_t[size + 1]; 
     read(buffer, size, stream);
     buffer[size] = 0; // null-terminator
-    pal::clr_palstring((const char*)buffer, &str);
+    pal::clr_palstring(reinterpret_cast<const char*>(buffer), &str);
 }
 
 static bool has_dirs_in_path(const pal::string_t& path)
@@ -257,7 +257,7 @@ FILE* bundle_runner_t::create_extraction_file(const pal::string_t& relative_path
 void bundle_runner_t::extract_file(file_entry_t *entry)
 {
     FILE* file = create_extraction_file(entry->relative_path());
-    const size_t buffer_size = 8 * 1024; // Copy the file in 8KB chunks
+    const int64_t buffer_size = 8 * 1024; // Copy the file in 8KB chunks
     uint8_t buffer[buffer_size];
     int64_t file_size = entry->size();
 
index ca08ee6..c1e43a8 100644 (file)
@@ -13,7 +13,7 @@ using namespace bundle;
 bool file_entry_t::is_valid()
 {
     return m_data.offset > 0 && m_data.size > 0 &&
-        (file_type_t)m_data.type < file_type_t::__last;
+        static_cast<file_type_t>(m_data.type) < file_type_t::__last;
 }
 
 file_entry_t* file_entry_t::read(FILE* stream)
index 961b63e..08d196c 100644 (file)
@@ -141,4 +141,4 @@ bool deps_entry_t::to_full_path(const pal::string_t& base, pal::string_t* str) c
     }
 
     return to_rel_path(new_base, str);
-}
\ No newline at end of file
+}
index 952332c..ea067ce 100644 (file)
@@ -12,9 +12,9 @@
 #include <cassert>
 #include <functional>
 
-const std::array<const pal::char_t*, deps_entry_t::asset_types::count> deps_entry_t::s_known_asset_types = {
+const std::array<const pal::char_t*, deps_entry_t::asset_types::count> deps_entry_t::s_known_asset_types = {{
     _X("runtime"), _X("resources"), _X("native")
-};
+}};
 
 const deps_entry_t& deps_json_t::try_ni(const deps_entry_t& entry) const
 {
@@ -84,7 +84,7 @@ void deps_json_t::reconcile_libraries_with_targets(
         pal::string_t library_hash_path = get_optional_path(properties, _X("hashPath"));
         pal::string_t runtime_store_manifest_list = get_optional_path(properties, _X("runtimeStoreManifestName"));
 
-        for (int i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
+        for (size_t i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
         {
             bool rid_specific = false;
             for (const auto& asset : get_assets_fn(library.first, i, &rid_specific))
@@ -106,7 +106,7 @@ void deps_json_t::reconcile_libraries_with_targets(
                 entry.library_path = library_path;
                 entry.library_hash_path = library_hash_path;
                 entry.runtime_store_manifest_list = runtime_store_manifest_list;
-                entry.asset_type = (deps_entry_t::asset_types) i;
+                entry.asset_type = static_cast<deps_entry_t::asset_types>(i);
                 entry.is_serviceable = serviceable;
                 entry.is_rid_specific = rid_specific;
                 entry.deps_file = deps_file;
@@ -231,7 +231,7 @@ bool deps_json_t::process_runtime_targets(const json_value& json, const pal::str
         for (const auto& file : files)
         {
             const auto& type = file.second.at(_X("assetType")).as_string();
-            for (int i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
+            for (size_t i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
             {
                 if (pal::strcasecmp(type.c_str(), deps_entry_t::s_known_asset_types[i]) == 0)
                 {
@@ -282,7 +282,7 @@ bool deps_json_t::process_targets(const json_value& json, const pal::string_t& t
     for (const auto& package : json.at(_X("targets")).at(target_name).as_object())
     {
         const auto& asset_types = package.second.as_object();
-        for (int i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
+        for (size_t i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
         {
             auto iter = asset_types.find(deps_entry_t::s_known_asset_types[i]);
             if (iter != asset_types.end())
index 69de7f9..f7533c1 100644 (file)
@@ -47,7 +47,7 @@ public:
         return fx_version_number;
     }
 
-    const bool get_apply_patches() const
+    bool get_apply_patches() const
     {
         return apply_patches;
     }
@@ -56,7 +56,7 @@ public:
         apply_patches = value;
     }
 
-    const roll_forward_option get_roll_forward() const
+    roll_forward_option get_roll_forward() const
     {
         return roll_forward;
     }
@@ -65,7 +65,7 @@ public:
         roll_forward = value;
     }
 
-    const bool get_prefer_release() const
+    bool get_prefer_release() const
     {
         return prefer_release;
     }
index d4eb972..00f561c 100644 (file)
@@ -49,4 +49,4 @@ public:
     const host_interface_t& get_host_init_data();
 };
 
-#endif // __COREHOST_INIT_H__
\ No newline at end of file
+#endif // __COREHOST_INIT_H__
index 1b1828a..b9f197a 100644 (file)
@@ -47,7 +47,7 @@ int load_hostpolicy(
     }
 
     // Obtain entrypoint symbol
-    *main_fn = (T)pal::get_symbol(*h_host, main_entry_symbol);
+    *main_fn = reinterpret_cast<T>(pal::get_symbol(*h_host, main_entry_symbol));
     if (*main_fn == nullptr)
         return StatusCode::CoreHostEntryPointFailure;
 
@@ -673,7 +673,7 @@ int fx_muxer_t::execute(
         {
             result = parse_args(host_info, 1, argc, argv, false, mode, &new_argoff, app_candidate, opts); // arg offset 1 for dotnet
 
-            if (result == AppArgNotRunnable)
+            if (static_cast<StatusCode>(result) == AppArgNotRunnable)
             {
                 return handle_cli(host_info, argc, argv);
             }
index 3e3b2ec..147c1f2 100644 (file)
@@ -190,14 +190,14 @@ namespace
         const pal::string_t & oldest_requested_version,
         const pal::string_t & dotnet_dir)
     {
-#if DEBUG
+#if defined(DEBUG)
         assert(!fx_ref.get_fx_name().empty());
         assert(!fx_ref.get_fx_version().empty());
 
         fx_ver_t _debug_ver;
         assert(fx_ver_t::parse(fx_ref.get_fx_version(), &_debug_ver, false));
         assert(_debug_ver == fx_ref.get_fx_version_number());
-#endif // DEBUG
+#endif // defined(DEBUG)
 
         trace::verbose(_X("--- Resolving FX directory, name '%s' version '%s'"),
             fx_ref.get_fx_name().c_str(), fx_ref.get_fx_version().c_str());
index 01b9c75..190d537 100644 (file)
@@ -71,4 +71,4 @@ private:
     fx_name_to_fx_reference_map_t m_oldest_fx_references;
 };
 
-#endif // __FX_RESOLVER_H__
\ No newline at end of file
+#endif // __FX_RESOLVER_H__
index 3b54d6b..d836eb5 100644 (file)
@@ -113,11 +113,12 @@ SHARED_API int32_t hostfxr_resolve_sdk(
         return 0;
     }
 
-    if (cli_sdk.size() < buffer_size)
+    unsigned long non_negative_buffer_size = static_cast<unsigned long>(buffer_size);
+    if (cli_sdk.size() < non_negative_buffer_size)
     {
-        size_t length = cli_sdk.copy(buffer, buffer_size - 1);
+        size_t length = cli_sdk.copy(buffer, non_negative_buffer_size - 1);
         assert(length == cli_sdk.size());
-        assert(length < buffer_size);
+        assert(length < non_negative_buffer_size);
         buffer[length] = 0;
     }
     else
index 504171f..b159960 100644 (file)
@@ -209,12 +209,12 @@ int hostpolicy_resolver::load(
         }
 
         // Obtain entrypoint symbols
-        g_hostpolicy_contract.load = (corehost_load_fn)pal::get_symbol(g_hostpolicy, "corehost_load");
-        g_hostpolicy_contract.unload = (corehost_unload_fn)pal::get_symbol(g_hostpolicy, "corehost_unload");
+        g_hostpolicy_contract.load = reinterpret_cast<corehost_load_fn>(pal::get_symbol(g_hostpolicy, "corehost_load"));
+        g_hostpolicy_contract.unload = reinterpret_cast<corehost_unload_fn>(pal::get_symbol(g_hostpolicy, "corehost_unload"));
         if ((g_hostpolicy_contract.load == nullptr) || (g_hostpolicy_contract.unload == nullptr))
             return StatusCode::CoreHostEntryPointFailure;
 
-        g_hostpolicy_contract.set_error_writer = (corehost_set_error_writer_fn)pal::get_symbol(g_hostpolicy, "corehost_set_error_writer");
+        g_hostpolicy_contract.set_error_writer = reinterpret_cast<corehost_set_error_writer_fn>(pal::get_symbol(g_hostpolicy, "corehost_set_error_writer"));
 
         // It's possible to not have corehost_set_error_writer, since this was only introduced in 3.0
         // so 2.0 hostpolicy would not have the export. In this case we will not propagate the error writer
@@ -322,4 +322,4 @@ bool hostpolicy_resolver::try_get_dir(
         }
     }
     return false;
-}
\ No newline at end of file
+}
index 12e2853..b9a9d4c 100644 (file)
@@ -56,7 +56,7 @@ namespace
 bool fxr_resolver::try_get_path(const pal::string_t& root_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path)
 {
     pal::string_t fxr_dir;
-#if FEATURE_APPHOST || FEATURE_LIBHOST
+#if defined(FEATURE_APPHOST) || defined(FEATURE_LIBHOST)
     // If a hostfxr exists in root_path, then assume self-contained.
     if (root_path.length() > 0 && library_exists_in_dir(root_path, LIBFXR_NAME, out_fxr_path))
     {
@@ -133,7 +133,6 @@ bool fxr_resolver::try_get_path(const pal::string_t& root_path, pal::string_t* o
 
 bool fxr_resolver::try_get_existing_fxr(pal::dll_t *out_fxr, pal::string_t *out_fxr_path)
 {
-    pal::dll_t fxr;
     if (!pal::get_loaded_library(LIBFXR_NAME, "hostfxr_main", out_fxr, out_fxr_path))
         return false;
 
@@ -150,4 +149,4 @@ pal::string_t fxr_resolver::dotnet_root_from_fxr_path(const pal::string_t &fxr_p
     // Path to hostfxr is: <dotnet_root>/host/fxr/<version>/<hostfxr_file>
     pal::string_t fxr_root = get_directory(get_directory(fxr_path));
     return get_directory(get_directory(fxr_root));
-}
\ No newline at end of file
+}
index f84365f..ee34835 100644 (file)
@@ -56,7 +56,7 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostNameToAppNameCall
 
     // Leak fxr
 
-    auto get_delegate_from_hostfxr = (hostfxr_get_delegate_fn)pal::get_symbol(fxr, "hostfxr_get_runtime_delegate");
+    auto get_delegate_from_hostfxr = reinterpret_cast<hostfxr_get_delegate_fn>(pal::get_symbol(fxr, "hostfxr_get_runtime_delegate"));
     if (get_delegate_from_hostfxr == nullptr)
         return StatusCode::CoreHostEntryPointFailure;
 
@@ -71,7 +71,7 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostNameToAppNameCall
         return status;
     }
 
-    return get_delegate_from_hostfxr(host_path.c_str(), dotnet_root.c_str(), app_path_to_use->c_str(), type, (void**)delegate);
+    return get_delegate_from_hostfxr(host_path.c_str(), dotnet_root.c_str(), app_path_to_use->c_str(), type, reinterpret_cast<void**>(delegate));
 }
 
 #endif //_COREHOST_CLI_FXR_RESOLVER_H_
index 2e9bb13..155632b 100644 (file)
@@ -52,7 +52,7 @@ int host_startup_info_t::parse(
     return 0;
 }
 
-const bool host_startup_info_t::is_valid(host_mode_t mode) const
+bool host_startup_info_t::is_valid(host_mode_t mode) const
 {
     if (mode == host_mode_t::libhost)
     {
index 3530171..2d85f69 100644 (file)
@@ -20,7 +20,7 @@ struct host_startup_info_t
         int argc,
         const pal::char_t* argv[]);
 
-    const bool is_valid(host_mode_t mode) const;
+    bool is_valid(host_mode_t mode) const;
 
     const pal::string_t get_app_name() const;
 
index 26cafe6..04f1d88 100644 (file)
@@ -24,8 +24,8 @@ arguments_t::arguments_t()
  *  o %DOTNET_SHARED_STORE% -- multiple delimited paths
  *  o dotnet.exe relative shared store\<arch>\<tfm>
  *  o Global location
- *      Windows: C:\Program Files (x86) or
- *      Unix: directory of dotnet on the path.\<arch>\<tfm>
+ *      Windows: global default location (Program Files) or globally registered location (registry) + store\<arch>\<tfm>
+ *      Linux/macOS: none (no global locations are considered)
  */
 void setup_shared_store_paths(const pal::string_t& tfm, host_mode_t host_mode,const pal::string_t& own_dir, arguments_t* args)
 {
index db90019..821f0d2 100644 (file)
@@ -62,10 +62,10 @@ namespace
             return false;
         }
 
-        coreclr_initialize = (coreclr_initialize_fn)pal::get_symbol(g_coreclr, "coreclr_initialize");
-        coreclr_shutdown = (coreclr_shutdown_fn)pal::get_symbol(g_coreclr, "coreclr_shutdown_2");
-        coreclr_execute_assembly = (coreclr_execute_assembly_fn)pal::get_symbol(g_coreclr, "coreclr_execute_assembly");
-        coreclr_create_delegate = (coreclr_create_delegate_fn)pal::get_symbol(g_coreclr, "coreclr_create_delegate");
+        coreclr_initialize = reinterpret_cast<coreclr_initialize_fn>(pal::get_symbol(g_coreclr, "coreclr_initialize"));
+        coreclr_shutdown = reinterpret_cast<coreclr_shutdown_fn>(pal::get_symbol(g_coreclr, "coreclr_shutdown_2"));
+        coreclr_execute_assembly = reinterpret_cast<coreclr_execute_assembly_fn>(pal::get_symbol(g_coreclr, "coreclr_execute_assembly"));
+        coreclr_create_delegate = reinterpret_cast<coreclr_create_delegate_fn>(pal::get_symbol(g_coreclr, "coreclr_create_delegate"));
 
         assert(coreclr_initialize != nullptr
             && coreclr_shutdown != nullptr
@@ -298,4 +298,4 @@ void coreclr_property_bag_t::enumerate(std::function<void(const pal::string_t&,
 {
     for (auto &kv : _properties)
         callback(kv.first, kv.second);
-}
\ No newline at end of file
+}
index ae12689..4de5d8e 100644 (file)
@@ -244,7 +244,7 @@ void deps_resolver_t::setup_probe_config(
     m_probes.push_back(probe_config_t::published_deps_dir());
 
     // The framework locations, starting with highest level framework.
-    for (int i = 1; i < m_fx_definitions.size(); ++i)
+    for (size_t i = 1; i < m_fx_definitions.size(); ++i)
     {
         if (pal::directory_exists(m_fx_definitions[i]->get_dir()))
         {
@@ -549,7 +549,7 @@ bool deps_resolver_t::resolve_tpa_list(
     }
 
     // Probe FX deps entries after app assemblies are added.
-    for (int i = 1; i < m_fx_definitions.size(); ++i)
+    for (size_t i = 1; i < m_fx_definitions.size(); ++i)
     {
         const auto& deps_entries = m_is_framework_dependent ? m_fx_definitions[i]->get_deps().get_entries(deps_entry_t::asset_types::runtime) : empty;
         for (const auto& entry : deps_entries)
@@ -648,7 +648,7 @@ void deps_resolver_t::resolve_additional_deps(const arguments_t& args, const dep
         }
         else
         {
-            for (int i = 1; i < m_fx_definitions.size(); ++i)
+            for (size_t i = 1; i < m_fx_definitions.size(); ++i)
             {
                 fx_ver_t most_compatible_deps_folder_version;
                 fx_ver_t framework_found_version;
@@ -833,7 +833,7 @@ bool deps_resolver_t::resolve_probe_dirs(
     for (const auto& additional_deps : m_additional_deps)
     {
         const auto additional_deps_entries = additional_deps->get_entries(asset_type);
-        for (const auto entry : additional_deps_entries)
+        for (const auto& entry : additional_deps_entries)
         {
             if (!add_package_cache_entry(entry, m_app_dir, 0))
             {
@@ -843,7 +843,7 @@ bool deps_resolver_t::resolve_probe_dirs(
     }
 
     // Add fx package locations to fx_dir
-    for (int i = 1; i < m_fx_definitions.size(); ++i)
+    for (size_t i = 1; i < m_fx_definitions.size(); ++i)
     {
         const auto& fx_entries = m_fx_definitions[i]->get_deps().get_entries(asset_type);
 
index 634c8ab..288020c 100644 (file)
@@ -95,7 +95,7 @@ public:
 
     bool valid(pal::string_t* errors)
     {
-        for (int i = 0; i < m_fx_definitions.size(); ++i)
+        for (size_t i = 0; i < m_fx_definitions.size(); ++i)
         {
             // Verify the deps file exists. The app deps file does not need to exist
             if (i != 0)
index ceed011..ed25f96 100644 (file)
@@ -169,7 +169,7 @@ int run_as_app(
     if (trace::is_enabled())
     {
         pal::string_t arg_str;
-        for (int i = 0; i < argv_local.size(); i++)
+        for (size_t i = 0; i < argv_local.size(); i++)
         {
             pal::string_t cur;
             pal::clr_palstring(argv_local[i], &cur);
@@ -207,7 +207,7 @@ int run_as_app(
     trace::info(_X("Execute managed assembly exit code: 0x%X"), exit_code);
 
     // Shut down the CoreCLR
-    hr = g_coreclr->shutdown((int*)&exit_code);
+    hr = g_coreclr->shutdown(reinterpret_cast<int*>(&exit_code));
     if (!SUCCEEDED(hr))
     {
         trace::warning(_X("Failed to shut down CoreCLR, HRESULT: 0x%X"), hr);
index aa933d7..8385dbb 100644 (file)
@@ -152,7 +152,7 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
     bool set_app_paths = false;
 
     // Runtime options config properties.
-    for (int i = 0; i < hostpolicy_init.cfg_keys.size(); ++i)
+    for (size_t i = 0; i < hostpolicy_init.cfg_keys.size(); ++i)
     {
         // Provide opt-in compatible behavior by using the switch to set APP_PATHS
         const pal::char_t *key = hostpolicy_init.cfg_keys[i].c_str();
@@ -198,4 +198,4 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
     }
 
     return StatusCode::Success;
-}
\ No newline at end of file
+}
index 95f68df..c6103f7 100644 (file)
@@ -42,7 +42,7 @@ bool hostpolicy_init_t::init(host_interface_t* input, hostpolicy_init_t* init)
 
         init->patch_roll_forward = input->patch_roll_forward;
         init->prerelease_roll_forward = input->prerelease_roll_forward;
-        init->host_mode = (host_mode_t)input->host_mode;
+        init->host_mode = static_cast<host_mode_t>(input->host_mode);
     }
     else
     {
@@ -64,10 +64,9 @@ bool hostpolicy_init_t::init(host_interface_t* input, hostpolicy_init_t* init)
         fx_requested_ver = input->fx_ver;
     }
 
-    int fx_count = 0;
     if (input->version_lo >= offsetof(host_interface_t, fx_names) + sizeof(input->fx_names))
     {
-        int fx_count = input->fx_names.len;
+        size_t fx_count = input->fx_names.len;
         assert(fx_count > 0);
         assert(fx_count == input->fx_dirs.len);
         assert(fx_count == input->fx_requested_versions.len);
@@ -84,7 +83,7 @@ bool hostpolicy_init_t::init(host_interface_t* input, hostpolicy_init_t* init)
         make_palstr_arr(input->fx_found_versions.len, input->fx_found_versions.arr, &fx_found_versions);
 
         init->fx_definitions.reserve(fx_count);
-        for (int i = 0; i < fx_count; ++i)
+        for (size_t i = 0; i < fx_count; ++i)
         {
             auto fx = new fx_definition_t(fx_names[i], fx_dirs[i], fx_requested_versions[i], fx_found_versions[i]);
             init->fx_definitions.push_back(std::unique_ptr<fx_definition_t>(fx));
index dc87045..db34a2a 100644 (file)
@@ -341,7 +341,7 @@ _ASYNCRTIMP const std::error_category & __cdecl platform_category();
 /// </summary>
 inline std::system_error __cdecl create_system_error(unsigned long errorCode)
 {
-    std::error_code code((int)errorCode, platform_category());
+    std::error_code code(static_cast<int>(errorCode), platform_category());
     return std::system_error(code, code.message());
 }
 
@@ -350,7 +350,7 @@ inline std::system_error __cdecl create_system_error(unsigned long errorCode)
 /// </summary>
 inline std::error_code __cdecl create_error_code(unsigned long errorCode)
 {
-    return std::error_code((int)errorCode, platform_category());
+    return std::error_code(static_cast<int>(errorCode), platform_category());
 }
 
 /// <summary>
index 798012b..77f354c 100644 (file)
@@ -630,7 +630,7 @@ enum SafeIntError
 #if defined SAFEINT_REMOVE_NOTHROW
 #define SAFEINT_NOTHROW
 #else
-#define SAFEINT_NOTHROW throw()
+#define SAFEINT_NOTHROW noexcept
 #endif
 
 namespace msl
@@ -5594,6 +5594,11 @@ public:
         *this = SafeInt< T, E >( (U)u );
     }
 
+    SafeInt(const SafeInt< T, E >& u) SAFEINT_NOTHROW
+    {
+        *this = u;
+    }
+
     template < typename U >
     SafeInt( const U& i ) SAFEINT_CPP_THROW
     {
index 4d7e583..8bcece4 100644 (file)
@@ -86,4 +86,4 @@
 #ifdef _Inout_updates_bytes_
 #undef _Inout_updates_bytes_
 #endif
-#define _Inout_updates_bytes_(x)
\ No newline at end of file
+#define _Inout_updates_bytes_(x)
index 7490c86..5dae3ec 100644 (file)
@@ -345,7 +345,7 @@ public:
         /// Is the current value a null value?
         /// </summary>
         /// <returns><c>true</c> if the value is a null value, <c>false</c> otherwise</returns>
-        bool is_null() const { return type() == Null; };
+        bool is_null() const { return type() == Null; }
 
         /// <summary>
         /// Is the current value a number value?
@@ -1471,6 +1471,8 @@ public:
         protected:
             _Value() {}
 
+            _Value(const _Value& other) {}
+
             virtual void format(std::basic_string<char>& stream) const
             {
                 stream.append("null");
index 95dbe03..69ec0d3 100644 (file)
@@ -34,7 +34,7 @@ using namespace web::json;
 using namespace utility;
 using namespace utility::conversions;
 
-std::array<signed char,128> _hexval = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+static std::array<signed char,128> _hexval = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                           0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1,
@@ -83,6 +83,8 @@ public:
           m_currentParsingDepth(0)
     { }
 
+    virtual ~JSON_Parser() { }
+
     struct Location
     {
         size_t m_line;
@@ -375,7 +377,7 @@ inline bool JSON_Parser<CharType>::ParseInt64(CharType first, uint64_t& value)
     auto ch = PeekCharacter();
     while (ch >= '0' && ch <= '9')
     {
-        unsigned int next_digit = (unsigned int)(ch - '0');
+        unsigned int next_digit = static_cast<unsigned int>(ch - '0');
         if (value > (ULLONG_MAX / 10) || (value == ULLONG_MAX/10 && next_digit > ULLONG_MAX%10))
             return false;
 
@@ -410,19 +412,19 @@ namespace
         return _wcstod_l(str, nullptr, utility::details::scoped_c_thread_locale::c_locale());
     }
 #else
-    static int __attribute__((__unused__)) print_llu(char* ptr, size_t n, unsigned long long val64)
+    static int print_llu(char* ptr, size_t n, unsigned long long val64)
     {
         return snprintf(ptr, n, "%llu", val64);
     }
-    static int __attribute__((__unused__)) print_llu(char* ptr, size_t n, unsigned long val64)
+    static int print_llu(char* ptr, size_t n, unsigned long val64)
     {
         return snprintf(ptr, n, "%lu", val64);
     }
-    static double __attribute__((__unused__)) anystod(const char* str)
+    static double anystod(const char* str)
     {
         return strtod(str, nullptr);
     }
-    static double __attribute__((__unused__)) anystod(const wchar_t* str)
+    static double anystod(const wchar_t* str)
     {
         return wcstod(str, nullptr);
     }
@@ -491,7 +493,7 @@ bool JSON_Parser<CharType>::CompleteNumberLiteral(CharType first, Token &token)
     ::std::vector<CharType> buf(::std::numeric_limits<uint64_t>::digits10 + 5);
     int count = print_llu(buf.data(), buf.size(), val64);
     _ASSERTE(count >= 0);
-    _ASSERTE((size_t)count < buf.size());
+    _ASSERTE(static_cast<size_t>(count) < buf.size());
     // Resize to cut off the null terminator
     buf.resize(count);
 
@@ -574,7 +576,7 @@ bool JSON_Parser<CharType>::CompleteNumberLiteral(CharType first, Token &token)
             // Not expected number character?
             break;
         }
-    };
+    }
 
     buf.push_back('\0');
     token.double_val = anystod(buf.data());
@@ -895,7 +897,7 @@ try_again:
     case '}':
     case ']':
         {
-            if((signed int)(--m_currentParsingDepth) < 0)
+            if(static_cast<signed int>(--m_currentParsingDepth) < 0)
             {
                 SetErrorCode(result, json_error::mismatched_brances);
                 break;
index 4aea3c8..a48374a 100644 (file)
@@ -51,8 +51,8 @@ namespace details
 {
 
 #if !defined(ANDROID) && !defined(__ANDROID__)
-std::once_flag g_c_localeFlag;
-std::unique_ptr<scoped_c_thread_locale::xplat_locale, void(*)(scoped_c_thread_locale::xplat_locale *)> g_c_locale(nullptr, [](scoped_c_thread_locale::xplat_locale *){});
+static std::once_flag g_c_localeFlag;
+static std::unique_ptr<scoped_c_thread_locale::xplat_locale, void(*)(scoped_c_thread_locale::xplat_locale *)> g_c_locale(nullptr, [](scoped_c_thread_locale::xplat_locale *){});
 scoped_c_thread_locale::xplat_locale scoped_c_thread_locale::c_locale()
 {
     std::call_once(g_c_localeFlag, [&]()
index 9deff2b..351d493 100644 (file)
@@ -53,4 +53,4 @@ NETHOST_API int NETHOST_CALLTYPE get_hostfxr_path(
     fxr_path.copy(buffer, len);
     buffer[len] = '\0';
     return StatusCode::Success;
-}
\ No newline at end of file
+}
index 25c82b8..1afb21b 100644 (file)
@@ -63,4 +63,4 @@ extern "C" NETHOST_API int NETHOST_CALLTYPE get_hostfxr_path(
     size_t * buffer_size,
     const char_t * assembly_path);
 
-#endif // __NETHOST_H__
\ No newline at end of file
+#endif // __NETHOST_H__
index dd08b0d..684e412 100644 (file)
@@ -461,6 +461,6 @@ bool runtime_config_t::mark_specified_setting(specified_setting setting)
         return false;
     }
 
-    m_specified_settings = (specified_setting)(m_specified_settings | setting);
+    m_specified_settings = static_cast<specified_setting>(m_specified_settings | setting);
     return true;
 }
index 6566fc7..3384a68 100644 (file)
@@ -35,7 +35,7 @@ SHARED_API pal::hresult_t STDMETHODCALLTYPE coreclr_initialize(
 
     if (hostHandle != nullptr)
     {
-        *hostHandle = (coreclr_t::host_handle_t*)(size_t) 0xdeadbeef;
+        *hostHandle = reinterpret_cast<coreclr_t::host_handle_t>(0xdeadbeef);
     }
 
     return StatusCode::Success;
@@ -139,7 +139,7 @@ typedef void (*CoreClrDelegate)();
 
 const int MaxDelegates = 16;
 
-MockCoreClrDelegate DelegateState[MaxDelegates];
+static MockCoreClrDelegate DelegateState[MaxDelegates];
 
 #define DelegateFunction(index)\
 void Delegate_ ## index() { DelegateState[index].Echo(); }
@@ -213,7 +213,7 @@ SHARED_API pal::hresult_t STDMETHODCALLTYPE coreclr_create_delegate(
 
     DelegateState[delegateIndex] = delegateState;
 
-    *delegate = (void*) delegates[delegateIndex];
+    *delegate = reinterpret_cast<void*>(delegates[delegateIndex]);
 
     return StatusCode::Success;
 }
index 97f1c37..3e2b711 100644 (file)
@@ -23,7 +23,7 @@ void print_strarr(const char* prefix, const strarr_t& arr)
         return;
     }
 
-    for (int i = 0; i < arr.len; i++)
+    for (size_t i = 0; i < arr.len; i++)
     {
         std::cout << prefix << tostr(arr.arr[i]).data() << std::endl;
     }
@@ -43,7 +43,7 @@ SHARED_API int corehost_load(host_interface_t* init)
     }
     else
     {
-        for (int i = 0; i < init->config_keys.len; i++)
+        for (size_t i = 0; i < init->config_keys.len; i++)
         {
             std::cout << "mock config: " << tostr(init->config_keys.arr[i]).data() << "=" << tostr(init->config_values.arr[i]).data() << std::endl;
         }
@@ -72,7 +72,7 @@ SHARED_API int corehost_load(host_interface_t* init)
     }
     else
     {
-        for (int i = 0; i < init->fx_names.len; i++)
+        for (size_t i = 0; i < init->fx_names.len; i++)
         {
             std::cout << "mock frameworks: " 
                 << tostr(init->fx_names.arr[i]).data() << " " 
index 5bb3a97..39d37af 100644 (file)
@@ -9,4 +9,4 @@ namespace comhost_test
     bool synchronous(const pal::string_t &comhost_path, const pal::string_t &clsid_str, int count);
 
     bool concurrent(const pal::string_t &comhost_path, const pal::string_t &clsid_str, int count);
-}
\ No newline at end of file
+}
index 352c80e..e81367e 100644 (file)
@@ -62,13 +62,13 @@ int main(const int argc, const pal::char_t *argv[])
         pal::string_t fxr_path;
         size_t len = fxr_path.size();
         int res = get_hostfxr_path(nullptr, &len, assembly_path);
-        if (res == StatusCode::HostApiBufferTooSmall)
+        if (static_cast<StatusCode>(res) == StatusCode::HostApiBufferTooSmall)
         {
             fxr_path.resize(len);
             res = get_hostfxr_path(&fxr_path[0], &len, assembly_path);
         }
 
-        if (res == StatusCode::Success)
+        if (static_cast<StatusCode>(res) == StatusCode::Success)
         {
             std::cout << "get_hostfxr_path succeeded" << std::endl;
             std::cout << "hostfxr_path: " << tostr(pal::to_lower(fxr_path)).data() << std::endl;
@@ -113,4 +113,4 @@ int main(const int argc, const pal::char_t *argv[])
         std::cerr << "Invalid arguments" << std::endl;
         return -1;
     }
-}
\ No newline at end of file
+}
index a987f7f..2fca39b 100644 (file)
@@ -43,4 +43,4 @@ private:
     static int compare(const version_t&a, const version_t& b);
 };
 
-#endif // __VERSION_H__
\ No newline at end of file
+#endif // __VERSION_H__
index de26da1..8417160 100644 (file)
@@ -37,7 +37,7 @@ pal::string_t pal::to_lower(const pal::string_t& in)
 
 pal::string_t pal::get_timestamp()
 {
-    std::time_t t = std::time(0);
+    std::time_t t = std::time(nullptr);
     const std::size_t elems = 100;
     char_t buf[elems];
     std::strftime(buf, elems, _X("%c %Z"), std::gmtime(&t));
@@ -318,7 +318,7 @@ bool pal::get_default_installation_dir(pal::string_t* recv)
 pal::string_t trim_quotes(pal::string_t stringToCleanup)
 {
     pal::char_t quote_array[2] = {'\"', '\''};
-    for(int index = 0; index < sizeof(quote_array)/sizeof(quote_array[0]); index++)
+    for(size_t index = 0; index < sizeof(quote_array)/sizeof(quote_array[0]); index++)
     {
         size_t pos = stringToCleanup.find(quote_array[index]);
         while(pos != std::string::npos)
@@ -347,7 +347,7 @@ pal::string_t pal::get_current_os_rid_platform()
     //
     // Needless to say, this will need to be updated if OSX RID were to become 11.* ever.
     size_t size = sizeof(str);
-    int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
+    int ret = sysctlbyname("kern.osrelease", str, &size, nullptr, 0);
     if (ret == 0)
     {
         std::string release(str, size);
index 79589ac..d4b750a 100644 (file)
@@ -130,7 +130,7 @@ void trace::error(const pal::char_t* format, ...)
 
     va_list dup_args;
     va_copy(dup_args, args);
-    int count = pal::str_vprintf(NULL, 0, format, args) + 1;
+    int count = pal::str_vprintf(nullptr, 0, format, args) + 1;
     std::vector<pal::char_t> buffer(count);
     pal::str_vprintf(&buffer[0], count, format, dup_args);
 
@@ -203,4 +203,4 @@ trace::error_writer_fn trace::get_error_writer()
 {
     // No need for locking since g_error_writer is thread local.
     return g_error_writer;
-}
\ No newline at end of file
+}
index 2a1c5cf..beddb4d 100644 (file)
@@ -143,12 +143,12 @@ pal::string_t get_directory(const pal::string_t& path)
         return ret + DIR_SEPARATOR;
     }
 
-    int pos = (int) path_sep;
+    int pos = static_cast<int>(path_sep);
     while (pos >= 0 && ret[pos] == DIR_SEPARATOR)
     {
         pos--;
     }
-    return ret.substr(0, (size_t)pos + 1) + DIR_SEPARATOR;
+    return ret.substr(0, static_cast<size_t>(pos) + 1) + DIR_SEPARATOR;
 }
 
 void remove_trailing_dir_seperator(pal::string_t* dir)
@@ -161,7 +161,7 @@ void remove_trailing_dir_seperator(pal::string_t* dir)
 
 void replace_char(pal::string_t* path, pal::char_t match, pal::char_t repl)
 {
-       int pos = 0;
+       size_t pos = 0;
     while ((pos = path->find(match, pos)) != pal::string_t::npos)
     {
         (*path)[pos] = repl;
@@ -170,7 +170,7 @@ void replace_char(pal::string_t* path, pal::char_t match, pal::char_t repl)
 
 pal::string_t get_replaced_char(const pal::string_t& path, pal::char_t match, pal::char_t repl)
 {
-       int pos = path.find(match);
+       size_t pos = path.find(match);
     if (pos == pal::string_t::npos)
     {
         return path;
@@ -187,13 +187,13 @@ pal::string_t get_replaced_char(const pal::string_t& path, pal::char_t match, pa
 
 const pal::char_t* get_arch()
 {
-#if _TARGET_AMD64_
+#if defined(_TARGET_AMD64_)
     return _X("x64");
-#elif _TARGET_X86_
+#elif defined(_TARGET_X86_)
     return _X("x86");
-#elif _TARGET_ARM_
+#elif defined(_TARGET_ARM_)
     return _X("arm");
-#elif _TARGET_ARM64_
+#elif defined(_TARGET_ARM64_)
     return _X("arm64");
 #else
 #error "Unknown target"
@@ -268,7 +268,7 @@ bool skip_utf8_bom(pal::istream_t* stream)
     }
 
     unsigned char bytes[3];
-    stream->read((char*) bytes, 3);
+    stream->read(reinterpret_cast<char*>(bytes), 3);
     if ((stream->gcount() < 3) ||
             (bytes[1] != 0xBB) || 
             (bytes[2] != 0xBF))
@@ -404,7 +404,7 @@ bool try_stou(const pal::string_t& str, unsigned* num)
     {
         return false;
     }
-    *num = (unsigned)std::stoul(str);
+    *num = std::stoul(str);
     return true;
 }
 
@@ -450,4 +450,4 @@ void get_runtime_config_paths(const pal::string_t& path, const pal::string_t& na
     dev_cfg->assign(dev_json_path);
 
     trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());
-}
\ No newline at end of file
+}
index 6d02483..3773705 100644 (file)
@@ -10,7 +10,7 @@
 #include "trace.h"
 #include "utils.h"
 
-#if FEATURE_APPHOST
+#if defined(FEATURE_APPHOST)
 #include "cli/apphost/bundle/bundle_runner.h"
 
 #define CURHOST_TYPE    _X("apphost")
@@ -72,7 +72,7 @@ bool is_exe_enabled_for_execution(pal::string_t* app_dll)
     trace::info(_X("The managed DLL bound to this executable is: '%s'"), app_dll->c_str());
     return true;
 }
-#elif !FEATURE_LIBHOST
+#elif !defined(FEATURE_LIBHOST)
 #define CURHOST_TYPE    _X("dotnet")
 #define CUREXE_PKG_VER  HOST_PKG_VER
 #define CURHOST_EXE
@@ -93,7 +93,7 @@ int exe_start(const int argc, const pal::char_t* argv[])
     pal::string_t app_root;
     bool requires_v2_hostfxr_interface = false;
     
-#if FEATURE_APPHOST
+#if defined(FEATURE_APPHOST)
     pal::string_t embedded_app_name;
     if (!is_exe_enabled_for_execution(&embedded_app_name))
     {
@@ -195,7 +195,7 @@ int exe_start(const int argc, const pal::char_t* argv[])
 
     // Obtain the entrypoints.
     int rc;
-    hostfxr_main_startupinfo_fn main_fn_v2 = (hostfxr_main_startupinfo_fn)pal::get_symbol(fxr, "hostfxr_main_startupinfo");
+    hostfxr_main_startupinfo_fn main_fn_v2 = reinterpret_cast<hostfxr_main_startupinfo_fn>(pal::get_symbol(fxr, "hostfxr_main_startupinfo"));
     if (main_fn_v2 != nullptr)
     {
         const pal::char_t* host_path_cstr = host_path.c_str();
@@ -207,7 +207,7 @@ int exe_start(const int argc, const pal::char_t* argv[])
         trace::info(_X("Dotnet path: [%s]"), dotnet_root.c_str());
         trace::info(_X("App path: [%s]"), app_path.c_str());
 
-        hostfxr_set_error_writer_fn set_error_writer_fn = (hostfxr_set_error_writer_fn)pal::get_symbol(fxr, "hostfxr_set_error_writer");
+        hostfxr_set_error_writer_fn set_error_writer_fn = reinterpret_cast<hostfxr_set_error_writer_fn>(pal::get_symbol(fxr, "hostfxr_set_error_writer"));
 
         {
             propagate_error_writer_t propagate_error_writer_to_hostfxr(set_error_writer_fn);
@@ -231,7 +231,7 @@ int exe_start(const int argc, const pal::char_t* argv[])
 
             // For compat, use the v1 interface. This requires additional file I\O to re-parse parameters and
             // for apphost, does not support DOTNET_ROOT or dll with different name for exe.
-            hostfxr_main_fn main_fn_v1 = (hostfxr_main_fn)pal::get_symbol(fxr, "hostfxr_main");
+            hostfxr_main_fn main_fn_v1 = reinterpret_cast<hostfxr_main_fn>(pal::get_symbol(fxr, "hostfxr_main"));
             if (main_fn_v1 != nullptr)
             {
                 rc = main_fn_v1(argc, argv);
@@ -323,4 +323,4 @@ int main(const int argc, const pal::char_t* argv[])
     return exit_code;
 }
 
-#endif
\ No newline at end of file
+#endif
index d594a13..03969b2 100644 (file)
@@ -189,8 +189,20 @@ if(WIN32)
     set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
     set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
 else()
+    add_compile_options(-Wall)
+    add_compile_options(-Wextra)
+    if(CMAKE_C_COMPILER_ID STREQUAL Clang)
+        # Uncomment to enable additional, but likely irrelvant, warnings. For
+        # example, this will warn about using c++11 features even when
+        # compiling with -std=c++11.
+        # add_compile_options(-Weverything)
+    endif()
+    add_compile_options(-Werror)
+    add_compile_options(-Wno-missing-field-initializers)
+    add_compile_options(-Wno-unused-function)
     add_compile_options(-Wno-unused-local-typedef)
-    add_compile_options(-Werror=reorder)
+    add_compile_options(-Wno-unused-macros)
+    add_compile_options(-Wno-unused-parameter)
 endif()
 
 # Older CMake doesn't support CMAKE_CXX_STANDARD and GCC/Clang need a switch to enable C++ 11