[Boost-bugs] [Boost C++ Libraries] #4649: token_functions.hpp (220) : fix for warning C4127 conditional expression is constant

Subject: [Boost-bugs] [Boost C++ Libraries] #4649: token_functions.hpp (220) : fix for warning C4127 conditional expression is constant
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-09-14 15:33:21


#4649: token_functions.hpp (220) : fix for warning C4127 conditional expression
is constant
-----------------------------------------------------------+----------------
 Reporter: Andrew Macgregor <aamacgregor@…> | Owner: jsiek
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: tokenizer
  Version: Boost 1.44.0 | Severity: Problem
 Keywords: isspace |
-----------------------------------------------------------+----------------
 MSVC gives a compiler warning for the following piece of code (starting at
 line 220) in token_functions.hpp:

 ----------
  if (sizeof(char_type) == 1)
    return std::isspace(c) != 0;
  else
    return std::iswspace(c) != 0;
 ----------

 The warning is obvious:
   warning C4127: conditional expression is constant

 The warning is causing automated project builds to fail when 'fail on
 warning' and /W4 (maximum warnings) are set.

 Please can you make the run-time check for sizeof(char_type)==1 into a
 compile-time check? A solution could be to change:

 ----------
  if (sizeof(char_type) == 1)
    return std::isspace(c) != 0;
  else
    return std::iswspace(c) != 0;
 ----------

 for something along the lines of

 ----------
  return check_isspace<traits, sizeof(char_type)>::value_for(c);
 ----------

 where check_isspace is defined as follows:
 ----------
  template <typename traits, size_t char_type_size>
  struct check_isspace
  {
    typedef typename traits::char_type char_type;

    static bool value_for(char_type c) { return std::iswspace(c)!=0; }
  };

  template <typename traits>
  struct check_isspace<traits, 1>
  {
    typedef typename traits::char_type char_type;

    static bool value_for(char_type c) { return std::isspace(c)!=0; }
  };
 ----------

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4649>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC