From 9b80e75b050c14e8fb69c554e11c30eac321a053 Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 08:53:11 +0100 Subject: [PATCH 1/5] Add #pragma once --- format.h | 2 ++ posix.h | 2 ++ test/gtest-extra.h | 2 ++ test/mock-allocator.h | 2 ++ test/posix-test.h | 2 ++ 5 files changed, 10 insertions(+) diff --git a/format.h b/format.h index 52e8d5b3..1f217b5e 100644 --- a/format.h +++ b/format.h @@ -25,6 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma once + #ifndef FMT_FORMAT_H_ #define FMT_FORMAT_H_ diff --git a/posix.h b/posix.h index a2cf2b13..8ae38bec 100644 --- a/posix.h +++ b/posix.h @@ -25,6 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma once + #ifndef FMT_POSIX_H_ #define FMT_POSIX_H_ diff --git a/test/gtest-extra.h b/test/gtest-extra.h index df9cb7f0..d34e8188 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -25,6 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma once + #ifndef FMT_GTEST_EXTRA_H_ #define FMT_GTEST_EXTRA_H_ diff --git a/test/mock-allocator.h b/test/mock-allocator.h index 7de1e1a0..8b23aaf6 100644 --- a/test/mock-allocator.h +++ b/test/mock-allocator.h @@ -25,6 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma once + #ifndef FMT_MOCK_ALLOCATOR_H_ #define FMT_MOCK_ALLOCATOR_H_ diff --git a/test/posix-test.h b/test/posix-test.h index 4768cb94..60242439 100644 --- a/test/posix-test.h +++ b/test/posix-test.h @@ -25,6 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#pragma once + #ifndef FMT_POSIX_TEST_H #define FMT_POSIX_TEST_H From a243548cecda20f4f784960868673246d67448bc Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 09:03:49 +0100 Subject: [PATCH 2/5] Silence "warning C4996: 'strcpy': This function or variable may be unsafe." on MSVC --- test/util-test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/util-test.cc b/test/util-test.cc index fd295525..8b8a20a1 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -699,9 +699,8 @@ void test_count_digits() { } TEST(UtilTest, StringRef) { - char space[100]; - std::strcpy(space, "some string"); - EXPECT_EQ(sizeof("some string") - 1, StringRef(space).size()); + char space[100] = "some string"; + EXPECT_EQ(std::strlen(space), StringRef(space).size()); } TEST(UtilTest, CountDigits) { From 02aeb79cdcecff46e4f7c25b5cc18d61ba8a48b6 Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 09:36:36 +0100 Subject: [PATCH 3/5] Silence "warning: declaration of '*' shadows a member of 'this' [-Wshadow]" on mingw-gcc --- format.cc | 9 +++++++++ posix.cc | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/format.cc b/format.cc index 1a6e4e22..124d552f 100644 --- a/format.cc +++ b/format.cc @@ -487,6 +487,11 @@ FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) { return 0; } +# ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wshadow" +# endif + FMT_FUNC void fmt::WindowsError::init( int error_code, StringRef format_str, ArgList args) { error_code_ = error_code; @@ -496,6 +501,10 @@ FMT_FUNC void fmt::WindowsError::init( base = std::runtime_error(w.str()); } +# ifdef __GNUC__ +# pragma GCC diagnostic pop +# endif + #endif FMT_FUNC void fmt::internal::format_system_error( diff --git a/posix.cc b/posix.cc index b4893cd6..f0b1bece 100644 --- a/posix.cc +++ b/posix.cc @@ -134,13 +134,13 @@ void fmt::File::close() { fmt::LongLong fmt::File::size() const { #ifdef _WIN32 - LARGE_INTEGER size = {}; + LARGE_INTEGER filesize = {}; HANDLE handle = reinterpret_cast(_get_osfhandle(fd_)); - if (!FMT_SYSTEM(GetFileSizeEx(handle, &size))) + if (!FMT_SYSTEM(GetFileSizeEx(handle, &filesize))) throw WindowsError(GetLastError(), "cannot get file size"); - FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(size.QuadPart), + FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(filesize.QuadPart), "return type of File::size is not large enough"); - return size.QuadPart; + return filesize.QuadPart; #else typedef struct stat Stat; Stat file_stat = Stat(); From d0e57e8639065b471184abbf67c30291e11c5e07 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 15 Feb 2015 16:52:00 +0800 Subject: [PATCH 4/5] Silence "warning: missing initializer for member '_SYSTEM_INFO::' [-Wmissing-field-initializers]" on mingw-gcc --- posix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posix.cc b/posix.cc index f0b1bece..d8f9bb62 100644 --- a/posix.cc +++ b/posix.cc @@ -228,7 +228,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) { long fmt::getpagesize() { #ifdef _WIN32 - SYSTEM_INFO si = {}; + SYSTEM_INFO si; GetSystemInfo(&si); return si.dwPageSize; #else From f30cd36196b558c263ae3f666fd8b0dee12aef94 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 15 Feb 2015 21:58:48 +0800 Subject: [PATCH 5/5] Revert "Add #pragma once" Not everyone like it This reverts commit 9b80e75b050c14e8fb69c554e11c30eac321a053. --- format.h | 2 -- posix.h | 2 -- test/gtest-extra.h | 2 -- test/mock-allocator.h | 2 -- test/posix-test.h | 2 -- 5 files changed, 10 deletions(-) diff --git a/format.h b/format.h index 1f217b5e..52e8d5b3 100644 --- a/format.h +++ b/format.h @@ -25,8 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#pragma once - #ifndef FMT_FORMAT_H_ #define FMT_FORMAT_H_ diff --git a/posix.h b/posix.h index 8ae38bec..a2cf2b13 100644 --- a/posix.h +++ b/posix.h @@ -25,8 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#pragma once - #ifndef FMT_POSIX_H_ #define FMT_POSIX_H_ diff --git a/test/gtest-extra.h b/test/gtest-extra.h index d34e8188..df9cb7f0 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -25,8 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#pragma once - #ifndef FMT_GTEST_EXTRA_H_ #define FMT_GTEST_EXTRA_H_ diff --git a/test/mock-allocator.h b/test/mock-allocator.h index 8b23aaf6..7de1e1a0 100644 --- a/test/mock-allocator.h +++ b/test/mock-allocator.h @@ -25,8 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#pragma once - #ifndef FMT_MOCK_ALLOCATOR_H_ #define FMT_MOCK_ALLOCATOR_H_ diff --git a/test/posix-test.h b/test/posix-test.h index 60242439..4768cb94 100644 --- a/test/posix-test.h +++ b/test/posix-test.h @@ -25,8 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#pragma once - #ifndef FMT_POSIX_TEST_H #define FMT_POSIX_TEST_H