public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/67990] New: compare() does not sort null characters in locale collation order
@ 2015-10-16 16:56 hstong at ca dot ibm.com
0 siblings, 0 replies; only message in thread
From: hstong at ca dot ibm.com @ 2015-10-16 16:56 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-10-16 16:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-16 16:56 [Bug libstdc++/67990] New: compare() does not sort null characters in locale collation order hstong at ca dot ibm.com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).