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

Types implicitly convertible to pointers aren't caught by non-void-pointer rejection #2598

Closed
TellowKrinkle opened this issue Nov 12, 2021 · 1 comment

Comments

@TellowKrinkle
Copy link

Attempting to format non-void, non-char pointers normally leads to a compiler error, but attempting to format a class with an implicit conversion to a non-void, non-char pointer (e.g. a wchar_t) is not caught.

Example (click to view on compiler explorer):

#include <fmt/core.h>

template <typename T>
struct Pointer {
    T* value;
    operator T*() const { return value; }
};

/*
// Errors as expected
std::string format(wchar_t* p) {
    return fmt::format("{}", p);
}

// Errors as expected
std::string format(int* p) {
    return fmt::format("{}", p);
}
*/

// Should error as well, but instead formats as void*
std::string format(Pointer<wchar_t> p) {
    return fmt::format("{}", p);
}

// Should error as well, but instead formats as void*
std::string format(Pointer<int> p) {
    return fmt::format("{}", p);
}
@vitaut
Copy link
Contributor

vitaut commented Nov 13, 2021

Turned this into an error in 5380ff4. Thanks for reporting.

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