Skip to content

(WIP) Small fixes and improvements - #108

Closed
CarterLi wants to merge 15 commits into
fmtlib:masterfrom
CarterLi:master
Closed

CarterLi wants to merge 15 commits into
fmtlib:masterfrom
CarterLi:master

Conversation

@CarterLi

Copy link
Copy Markdown
Contributor

Good project, very fast and portable! When I was using cppformat as a tiny logging library for my project, I found some improvements. Not finished yet, but I decided to create PR earlier for everyone's reviewing.

Changes:

  1. Added some methods to BufferedFile to write raw texts without formating ( useful when writing logs )
  2. Use more amesome C++11 features
    • Deleted functions
    • Use static assertion actively
    • Change 0 to nullptr where appropriate
  3. Improve Windows / MSVC support
    • Use throw() in MSVC
    • Link with format.lib automatically in MSVC
    • Silence some warnings
  4. CMakeLists.txt improvements
    • Enable C++11 support when building main lib too ( why we didn't enable it before? )
    • Try to support clang: use libc++ when building with clang for better C++11 support ( doesn't work yet )

TODOs:

  • One warning remaining: format.cc:491:55: warning: declaration of 'error_code' shadows a member of 'this' [-Wshadow]
  • UT for extra methods added for BufferedFile. I'm not familier with gmock, investigating
  • Fix clang support. Currently cmake complains Could NOT find Threads (missing: Threads_FOUND). Don't know what's happening:(

Tested platforms

  1. Windows MSVC 2013
  2. Windows MSYS2 g++ 4.9.2
  3. Archlinux g++ 4.9.2
  4. Archlinux clang++ 3.5.1 with libc++

Thanks
Carter

carterl and others added 12 commits February 11, 2015 09:16
1. Remove initializers of out parameters: warning: missing initializer for member '_SYSTEM_INFO::dwPageSize' [-Wmissing-field-initializers]
2. Rename a local variable: warning: declaration of 'size' shadows a member of 'this' [-Wshadow]
Since it's hard to find all places where using 0 as a pointer literal, only format.* & posix.* are replaced ( missing expected though )
@CarterLi

Copy link
Copy Markdown
Contributor Author

g++ supports nullptr before change __cplusplus to 201103 in 4.6, will fix it

EDIT: We have other feature-testing macros using __cplusplus

# define FMT_USE_VARIADIC_TEMPLATES \
   (FMT_HAS_FEATURE(cxx_variadic_templates) || \
       (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L) || _MSC_VER >= 1800)

Which won't work for g++4.6 and below

@vitaut

vitaut commented Feb 13, 2015

Copy link
Copy Markdown
Contributor

Thanks for your interest in C++ Format and a huge contribution.

A few comments:

  1. New BufferedFile methods overall look good, but
    • I'd rename write_raw to write. The idea is to mostly follow the naming of the underlying methods, fwrite in this cases.

    • The following checks shouldn't be there, because calling a method on a closed file should fail in one way or another, not silently do nothing:

      if (!file_)
        return;
  2. FMT_NOEXCEPT without an argument: great idea, can merge it any time (if you submit it in a separate PR).
  3. nullptr: I'm afraid this change can't go in, because the library shouldn't define any unprefixed macro to avoid potential conflicts and warnings in the client code (however unlikely they are). It is possible to use FMT_NULLPTR instead, but it's probably make the code to ugly and not worth it. So I suggest keeping 0 for now. I have plans to write a small program that will do automatic translation of some C++11 constructs into C++98 that will address this issue.

In general, it would be nice to split it in several PRs if it is not too difficult. As I said the FMT_NOEXCEPT can go in right now and BufferedFile methods with only minor modifications.

Cheers!

@CarterLi

Copy link
Copy Markdown
Contributor Author

Thanks for your reply.

  1. I'd rename write_raw to write. The idea is to mostly follow the naming of the underlying methods, fwrite in this cases.
    • Have thought before. Concern: we already have fmt::MemoryWriter::write, which looks like fmt::BufferedFile::write. But they have different behavior: It's ok to say somefile.write("{}{}{}"), but you will get a fmt::FormatError exception when you run the same code for MemoryWriter
  2. The following checks shouldn't be there, because calling a method on a closed file should fail in one way or another, not silently do nothing
    • I agree. Will throw an exception.
  3. nullptr: I'm afraid this change can't go in
    • Well, nullptr is one of the cleanest feature in C++11 in my opinion. Too bad we can't use it for supporting ancient compilers. Ok I'll revert the change by some simple %s/nullptr/0/g

As there are some FIXMEs left, I don't expect a quick merge. Other comments are welcomed.

@CarterLi

Copy link
Copy Markdown
Contributor Author

Will split this into several smaller PRs, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants