Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm seeing inconsistent behavior in a call to std::isblank between Visual C++ on Windows and gcc on Ubuntu and I'm wondering which one is correct.

On both compilers -- when the default locale is the "C" locale -- the following call returns false

std::isblank('\n');  

This is what I expect. And it squares with what I see on cppreference.com

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

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

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

Here I am supplying std::locale::classic. Shouldn't that be the equivalent to the previous call? Because when I call this second version on Windows, it returns true. It considers a newline to be a blank character. Linux still says false.

Is my understanding (about std::locale::classic) correct? And if so, is the Visual C++ version wrong?

like image 581
Joe Avatar asked Mar 14 '18 21:03

Joe


1 Answers

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

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

  2. Returns: A locale that implements the classic "C" locale semantics, equivalent to the value locale("C").

  3. Remarks: This locale, its facets, and their member functions, do not change with time.

Thus the following:

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

Is the same as:

std::isblank('\n');  
 

Where locale("C") has been called.

like image 61
NathanOliver Avatar answered Sep 27 '22 18:09

NathanOliver