Fix compile checks for mixing narrow and wide strings (#690)

This commit is contained in:
Victor Zverovich 2018-03-30 09:29:47 -10:00
parent c5ebecf7c6
commit e8e006f4e7
2 changed files with 7 additions and 2 deletions

View File

@ -619,8 +619,8 @@ FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
// pointer cast it to "void *" or "const void *". In particular, this forbids
// formatting of "[const] volatile char *" which is printed as bool by
// iostreams.
template <typename T>
void make_value(const T *) {
template <typename C, typename T>
typed_value<C, pointer_type> make_value(const T *) {
static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
}

View File

@ -10,6 +10,7 @@ function (generate_source result fragment)
set(${result} "
#define FMT_HEADER_ONLY 1
#include \"fmt/posix.h\"
#include \"fmt/ostream.h\"
int main() {
${fragment}
}
@ -53,6 +54,10 @@ expect_compile_error("fmt::format(\"{}\", L'a');")
# Formatting a wide string with a narrow format string is forbidden.
expect_compile_error("fmt::format(\"{}\", L\"foo\");")
# Formatting a narrow string with a wide format string is forbidden because
# mixing UTF-8 with UTF-16/32 can result in an invalid output.
expect_compile_error("fmt::format(L\"{}\", \"foo\");")
# Make sure that compiler features detected in the header
# match the features detected in CMake.
if (SUPPORTS_USER_DEFINED_LITERALS)