<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 --- - auto deduces char* instead of const char*"
href="http://llvm.org/bugs/show_bug.cgi?id=16579">16579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>auto deduces char* instead of const char*
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jbt@gmx.us
</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>strchr is overloaded - the return value is the same type as the first argument.
However, initializing a variable with the const char* overload causes the
variable to have the type char*
Example (demo.cc):
#include <cstring>
void foo()
{
const char* a = "Hello Whirled!";
auto b = strchr(a, 'W');
b = a;
}
command (on the version from a recent Fedora release's repo):
$clang++ -c -std=c++11 demo.cc
demo.cc:6:7: error: assigning to 'char *' from incompatible type 'const char *'
b = a;
^ ~
1 error generated.
$clang++ --version
clang version 3.3 (tags/RELEASE_33/rc2)
Target: x86_64-redhat-linux-gnu
Thread model: posix
A recent version from svn exhibits exactly the same behavior:
$ clang++ --version
clang version 3.4 (trunk 185587)
Target: x86_64-unknown-linux-gnu
Thread model: posix
For reference, g++ does not have this particular problem:
$g++ -c -std=c++11 demo.cc
$g++ --version
g++ (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Copyright (C) 2012 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.</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>