[LLVMbugs] [Bug 16579] New: auto deduces char* instead of const char*

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 9 14:10:31 PDT 2013


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

            Bug ID: 16579
           Summary: auto deduces char* instead of const char*
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jbt at gmx.us
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
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/20130709/81a86fff/attachment.html>


More information about the llvm-bugs mailing list