Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RElesgoe opened this issue Aug 23, 2016 · 1 comment
Closed

Comments

@RElesgoe
Copy link

RElesgoe commented Aug 23, 2016

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.

@vitaut
Copy link
Contributor

vitaut commented Aug 23, 2016

Fixed in a79c7b4. Thanks!

@vitaut vitaut closed this as completed Aug 23, 2016
foonathan pushed a commit that referenced this issue Oct 23, 2016
foonathan pushed a commit that referenced this issue Oct 23, 2016
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

No branches or pull requests

2 participants