Skip to content

Compile error when passing a pointer to a non-const array of unsigned char #373

Closed
@RElesgoe

Description

@RElesgoe

Tested with fmt 3.0.0 release and commit 6c184ef (the latest at the time of writing) using Visual Studio 2015 Update 3.

Example program:

#include <cstdio>

#include "fmt/format.h"

int main()
{
    unsigned char message[6] = "Hello";

    unsigned char* pmessage = message;

    std::printf("%s\n", message); // OK
    fmt::print("{}\n", message); // OK

    std::printf("%s\n", pmessage); // OK
    fmt::print("{}\n", pmessage); // FAIL

    return 0;
}

Compiler output:

1>c:\fmt_test\fmt_test\fmt\format.h(2119): error C2248: 'fmt::internal::MakeValue<Formatter>::MakeValue': cannot access private member declared in class 'fmt::internal::MakeValue<Formatter>'
1>                 with
1>                 [
1>                     Formatter=fmt::BasicFormatter<char,fmt::ArgFormatter<char>>
1>                 ]
1>         c:\fmt_test\fmt_test\fmt\format.h(1186): note: see declaration of 'fmt::internal::MakeValue<Formatter>::MakeValue'
1>                 with
1>                 [
1>                     Formatter=fmt::BasicFormatter<char,fmt::ArgFormatter<char>>
1>                 ]
1>         c:\fmt_test\fmt_test\fmt\format.h(2119): note: see declaration of 'fmt::internal::MakeValue<Formatter>'
1>                 with
1>                 [
1>                     Formatter=fmt::BasicFormatter<char,fmt::ArgFormatter<char>>
1>                 ]
1>         c:\fmt_test\fmt_test\fmt\format.h(3469): note: see reference to function template instantiation 'fmt::internal::Value fmt::internal::ArgArray<1,true>::make<fmt::BasicFormatter<Char,fmt::ArgFormatter<Char>>,unsigned char*>(const T &)' being compiled
1>                 with
1>                 [
1>                     Char=char,
1>                     T=unsigned char *
1>                 ]
1>         c:\fmt_test\fmt_test\fmt\format.h(3469): note: see reference to function template instantiation 'fmt::internal::Value fmt::internal::ArgArray<1,true>::make<fmt::BasicFormatter<Char,fmt::ArgFormatter<Char>>,unsigned char*>(const T &)' being compiled
1>                 with
1>                 [
1>                     Char=char,
1>                     T=unsigned char *
1>                 ]
1>         c:\fmt_test\fmt_test\main.cpp(15): note: see reference to function template instantiation 'void fmt::print<unsigned char*>(fmt::CStringRef,unsigned char *const &)' being compiled

Changing the type of pmessage from unsigned char* to const unsigned char* will compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions