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

Unexpected compile time error when forbidden rvalue operator const char* #1421

Closed
Alek86 opened this issue Nov 25, 2019 · 1 comment
Closed

Comments

@Alek86
Copy link

Alek86 commented Nov 25, 2019

Maybe it's a known limitation, sorry for bothering in this case.
This code generates a compiler error (tried with VS 2015 and godbolt with clang 6.0.0):

#include <fmt/core.h>
class PString {
public:
    const char* c_str() const { return "11"; }
    operator const char*() const& { return c_str(); }
    operator const char*()& { return c_str(); }
    operator const char*() const&& = delete;
    operator const char*()&& = delete;
};
int main() {
    PString str;
    fmt::print("{}", str);
}

Not a big deal, because it's easily bypassed by adding code below. But maybe you want to address it anyway.

template <>
struct fmt::formatter<PString> {
  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
  template <typename FormatContext>
  auto format(const PString& ct, FormatContext& ctx) {
    return format_to(ctx.out(), "{}", ct.c_str());
  }
};
@vitaut
Copy link
Contributor

vitaut commented Nov 25, 2019

Should be fixed in 99b6e92. Thanks for reporting.

@vitaut vitaut closed this as completed Nov 25, 2019
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