<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Rejects valid for alleged duplicate case label when proper conversion yields different results"
href="http://llvm.org/bugs/show_bug.cgi?id=20461">20461</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Rejects valid for alleged duplicate case label when proper conversion yields different results
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Other
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hstong@ca.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>