http://llvm.org/bugs/show_bug.cgi?id=12548

             Bug #: 12548
           Summary: clang++ -fshort-wchar results in unsigned wchar_t
                    arithmetic (missing integral promotion)
           Product: clang
           Version: 3.0
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified


#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);
        return 0;
}


$ 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
$ g++ -Wall -fshort-wchar -o wchar wchar.cpp
$ ./wchar
-1 -1


Probably related to Bug 8856

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to