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

please add support to fmt::printf for passing volatile arguments #1586

Closed
janwilmans opened this issue Mar 11, 2020 · 2 comments
Closed

please add support to fmt::printf for passing volatile arguments #1586

janwilmans opened this issue Mar 11, 2020 · 2 comments

Comments

@janwilmans
Copy link

https://godbolt.org/z/R2rR5j

#define FMT_HEADER_ONLY
#include <fmt/printf.h>

struct foo
{
    enum fooEnum { test };
    fooEnum i;
};

int main()
{
    volatile foo f; 
    
    printf("%d", f.i);
    std::string s = fmt::sprintf("%d", f.i); // 
}

gives:

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/core.h: In instantiation of 'fmt::v6::internal::value<Context>::value(const T&) [with T = volatile foo::fooEnum; Context = fmt::v6::basic_printf_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char>]':

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/core.h:1122:39:   required from 'fmt::v6::internal::value<Context> fmt::v6::internal::make_arg(const T&) [with bool IS_PACKED = true; Context = fmt::v6::basic_printf_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char>; T = volatile foo::fooEnum; typename std::enable_if<IS_PACKED, int>::type <anonymous> = 0]'

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/core.h:1212:58:   required from 'fmt::v6::format_arg_store<Context, Args>::format_arg_store(const Args& ...) [with Context = fmt::v6::basic_printf_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char>; Args = {volatile foo::fooEnum}]'

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/core.h:1226:18:   required from 'fmt::v6::format_arg_store<Context, Args ...> fmt::v6::make_format_args(const Args& ...) [with Context = fmt::v6::basic_printf_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char>; Args = {volatile foo::fooEnum}]'

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/printf.h:618:77:   required from 'std::basic_string<Char> fmt::v6::sprintf(const S&, const Args& ...) [with S = char [3]; Args = {volatile foo::fooEnum}; Char = char]'

<source>:15:43:   required from here

/opt/compiler-explorer/libs/fmt/6.1.0/include/fmt/core.h:798:18: error: invalid conversion from 'const volatile void*' to 'const void*' [-fpermissive]

     custom.value = &val;
@vitaut
Copy link
Contributor

vitaut commented Mar 11, 2020

Should be fixed in f72a905. Thanks for reporting.

@vitaut vitaut closed this as completed Mar 11, 2020
@janwilmans
Copy link
Author

This also fixed: https://godbolt.org/z/GW7G_9

enum class Foo
{
    somevalue
};

int main()
{
    Foo f{};

    printf("%d", f);
    std::string s = fmt::sprintf("%d", f);
}

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