[LLVMbugs] [Bug 20461] New: Rejects valid for alleged duplicate case label when proper conversion yields different results
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat Jul 26 12:06:23 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20461
Bug ID: 20461
Summary: Rejects valid for alleged duplicate case label when
proper conversion yields different results
Product: clang
Version: trunk
Hardware: Other
OS: other
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: hstong at ca.ibm.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
The constraint on duplicate case labels is for having the same value after
conversion to the promoted type of the switch condition (C++03 subclause 6.4.2
[stmt.switch]).
In the following program, the expression val + 0 has the type which is the
promoted type of char (char must promote to int or unsigned int).
Both switches ought to compile; however, Clang compiles the first but not the
second.
GCC and EDG accept both switch statements.
### SOURCE:
$ cat casedup.cc
void foo(unsigned char val) {
switch (val + 0) {
case (unsigned char)-1:
case (unsigned short)-1:
;
}
switch (val) {
case (unsigned char)-1:
case (unsigned short)-1:
;
}
}
### COMPILER INVOCATION AND OUTPUT:
$ clang++ casedup.cc -c
casedup.cc:9:12: warning: overflow converting case value to switch condition
type (65535 to 255) [-Wswitch]
case (unsigned short)-1:
^
casedup.cc:9:12: error: duplicate case value '255'
casedup.cc:8:12: note: previous case defined here
case (unsigned char)-1:
^
1 warning and 1 error generated.
### EXPECTED BEHAVIOUR:
Clean compile.
### COMPILER VERSION INFO:
$ clang++ -v
clang version 3.5.0 (trunk 212631)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140726/2d04e57a/attachment.html>
More information about the llvm-bugs
mailing list