Inconsistent return from std :: isblank between Visual C ++ and gcc. Which one is wrong?

I see inconsistent behavior when calling std::isblank between Visual C ++ on Windows and gcc on Ubuntu, and I wonder which one is correct.

In both compilers - when the locale is by default the C locale, the next call returns false

 std::isblank('\n'); 

This is what I expect. And he squares what I see at cppreference.com

In the default locale C, only a space (0x20) and a horizontal tab (0x09) are classified as empty characters.

However, with C ++, we also have a version that takes the argument std::locale

 std::isblank('\n', std::locale::classic()); 

Here I will put std::locale::classic . Shouldn't that be equivalent to the previous call? Because when I invoke this second version on Windows, it returns true. He considers the new line empty. Linux still says false.

As far as I understand (near std::locale::classic )? And if so, is the version of Visual C ++ incorrect?

+8
c ++ gcc visual-studio locale
source share
1 answer

Yes, MSVS is wrong. [locale.statics] :

 static const locale& classic(); 
  1. Locale "C".

  2. Returns: a locale that implements the classical semantics of the C language, equivalent to the value language ("C").

  3. Notes: This language, its faces, and their member functions do not change over time.

So the following:

 std::isblank('\n', std::locale::classic()); 

Same as:

 std::isblank('\n'); 

Here is the locale("C") .

+5
source share

All Articles