fshort-wchar
fshort-wchar
- Subject: fshort-wchar
- From: Anders Markussen <email@hidden>
- Date: Fri, 13 Apr 2012 14:36:23 +0200
There seems to be a problem in clang with integral promotions on wchar_t with -fshort-wchar.
Using Xcode 4.2.1 / clang 3.0
#include <stdlib.h>
#include <stdio.h>
int compare(void const* ap, void const* bp) {
const wchar_t *a=(const wchar_t *)ap, *b=(const wchar_t *)bp;
while (*a && *b && (*a == *b)) {
++a; ++b;
}
return *a-*b;
}
int main() {
const wchar_t* fruit[] = { L"apricot",L"banana" };
printf("%d %d\n", L'a'-L'b', compare(fruit[0], fruit[1]));
qsort(fruit, 2, sizeof(wchar_t*), compare);
// At this point, in clang, the array has been mis-sorted.
return 0;
}
$ g++ -Wall -fshort-wchar -o wchar wchar.cpp
$ ./wchar
-1 -1
$ clang++ -Wall -fshort-wchar -o wchar wchar.cpp
wchar.cpp:14:11: warning: conversion specifies type 'int' but the argument has
type 'wchar_t' [-Wformat]
printf("%d %d\n", L'a'-L'b', compare(fruit[0], fruit[1]));
~^ ~~~~~~~~~
1 warning generated.
$ ./wchar
65535 65535
Known? Intended? It hurts our transition from llvm-gcc 4.2 to clang.
- Anders Markussen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden