Skip to content

Commit

Permalink
Don't inject internal names into std (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 17, 2019
1 parent 544b927 commit d306585
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ namespace internal {
#endif

// A fallback implementation of uintptr_t for systems that lack it.
namespace uintptr {
struct uintptr_t {
unsigned char value[sizeof(void*)];
};
}
using uintptr::uintptr_t;
typedef std::numeric_limits<uintptr_t> numutil;

template <typename T> inline bool use_grisu() {
Expand Down Expand Up @@ -312,7 +315,7 @@ typename Allocator::value_type* allocate(Allocator& alloc, std::size_t n) {
FMT_END_NAMESPACE

namespace std {
using namespace fmt::v5::internal;
using namespace fmt::v5::internal::uintptr;
// Standard permits specialization of std::numeric_limits. This specialization
// is used to detect presence of uintptr_t.
template <>
Expand Down
5 changes: 5 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,11 @@ TEST(FormatTest, EmphasisNonHeaderOnly) {
}

TEST(FormatTest, CharTraitsIsNotAmbiguous) {
// Test that we don't inject internal names into the std namespace.
using namespace std;
char_traits<char>::char_type c;
#if __cplusplus >= 201103L
std::string s;
begin(s);
#endif
}

0 comments on commit d306585

Please sign in to comment.