Skip to content

Commit

Permalink
Fixed clang -Wreserved-identifier warings
Browse files Browse the repository at this point in the history
Created FMT_UNCHECKED_TYPE that resolves to special identifier _Unchecked_type for Microsoft, but to a dummy string otherwise. Using
_Unchecked_type is invalid because underscore + uppercase is a reserved identifier.
  • Loading branch information
seanm committed Mar 9, 2022
1 parent 598df12 commit b30e335
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_

#include "core.h"
#include "format.h"

FMT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -36,7 +37,7 @@ template <typename OutputIt> class truncating_iterator_base {
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = void;
using _Unchecked_type =
using FMT_UNCHECKED_TYPE =
truncating_iterator_base; // Mark iterator as checked.

OutputIt base() const { return out_; }
Expand Down
8 changes: 7 additions & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@
# endif
#endif

#ifdef _MSC_VER
# define FMT_UNCHECKED_TYPE _Unchecked_type
#else
# define FMT_UNCHECKED_TYPE DummyName
#endif

#ifndef FMT_BEGIN_NAMESPACE
# define FMT_BEGIN_NAMESPACE \
namespace fmt { \
Expand Down Expand Up @@ -1498,7 +1504,7 @@ class appender : public std::back_insert_iterator<detail::buffer<char>> {
public:
using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
appender(base it) noexcept : base(it) {}
using _Unchecked_type = appender; // Mark iterator as checked.
using FMT_UNCHECKED_TYPE = appender; // Mark iterator as checked.

auto operator++() noexcept -> appender& { return *this; }

Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ class counting_iterator {
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = void;
using _Unchecked_type = counting_iterator; // Mark iterator as checked.
using FMT_UNCHECKED_TYPE = counting_iterator; // Mark iterator as checked.

struct value_type {
template <typename T> void operator=(const T&) {}
Expand Down

0 comments on commit b30e335

Please sign in to comment.