<html>
<head>
<base href="https://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 --- - Type alias fails in namespace std?"
href="https://llvm.org/bugs/show_bug.cgi?id=31658">31658</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Type alias fails in namespace std?
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hfinkel@anl.gov
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>A user of mine is trying to compile ROOT using Clang/libc++, and has code that
essentially does this:
$ cat /tmp/t2.cpp
#include <experimental/string_view>
namespace std {
template<class T, class Traits = std::char_traits<T>>
using basic_string_view = ::std::experimental::basic_string_view<T, Traits>;
typedef basic_string_view<char> string_view;
}
(the actual code in questions is <a href="https://root.cern.ch/root/html/RStringView.h">https://root.cern.ch/root/html/RStringView.h</a>).
And this fails like so:
/tmp/t2.cpp:6:9: error: unknown type name 'basic_string_view'
typedef basic_string_view<char> string_view;
^
/tmp/t2.cpp:6:26: error: expected unqualified-id
typedef basic_string_view<char> string_view;
^
2 errors generated.
If I change the 'namespace std' to 'namespace anythingelse', then it compiles
without a problem. Also, changing the name of the type alias to something other
than basic_string_view makes it work. Specifically, I'm using (r292097):
$ clang -stdlib=libc++ -fsyntax-only /tmp/t2.cpp -std=c++14
I realize that users shouldn't add things to namespace std, but I'm trying to
figure out what's going wrong here. I feel like I'm overlooking something
obvious, but maybe this is a bug? If not, the error could certainly be more
informative.
If I change the code to be:
#include <experimental/string_view>
namespace std {
inline namespace __1 {
template<class T, class Traits = std::char_traits<T>>
using basic_string_view = ::std::experimental::basic_string_view<T, Traits>;
typedef basic_string_view<char> string_view;
}
}
then I do get an explicit error:
/tmp/t2.cpp:6:1: error: redefinition of 'basic_string_view' as different kind
of symbol
using basic_string_view = ::std::experimental::basic_string_view<T, Traits>;
^
/include/c++/v1/string_view:180:29: note: previous definition is here
class _LIBCPP_TYPE_VIS_ONLY basic_string_view {
^
1 error generated.
Maybe we should generate a similar error in the original case as well?</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>