https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67990

            Bug ID: 67990
           Summary: compare() does not sort null characters in locale
                    collation order
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

Created attachment 36527
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36527&action=edit
Script to create REVNUL locale

collate::compare() does not respect the collation order when given a locale
definition where NULL is not sorted before all other characters.

A script (suitable for Linux systems) to produce a "REVNUL" locale into the
current working directory is attached.

REVNUL collates by ASCII value ordering except that NULL is placed after DELETE
and the uppercase letters are transposed with the lowercase ones.


### SOURCE:> cat nulsort.cc
#include <cassert>
#include <locale>

std::locale revnul("REVNUL");
const std::collate<char> &col = std::use_facet<std::collate<char> >(revnul);

int colcmp(const char c, const char d) {
  return col.compare(&c, &c + 1, &d, &d + 1);
}

int main(void) {
  const char sorted[] = { 'a', 'b', 'A', 'B', '\0' };
  assert(colcmp(sorted[0], sorted[1]) < 0);
  assert(colcmp(sorted[1], sorted[2]) < 0);
  assert(colcmp(sorted[2], sorted[3]) < 0);
  assert(colcmp(sorted[3], sorted[4]) < 0);
}
Return:  0x00:0


### COMPILER INVOCATION:> g++ nulsort.cc
Return:  0x00:0


### ACTUAL OUTPUT:> LOCPATH="$PWD" ./a.out
a.out: nulsort.cc:16: int main(): Assertion `colcmp(sorted[3], sorted[4]) < 0'
failed.
Aborted (core dumped)
Return:  0x86:134


### EXPECTED OUTPUT:
No assertion failure


### COMPILER VERSION INFO:> g++ --version
g++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Return:  0x00:0

Reply via email to