[llvm-bugs] [Bug 31658] New: Type alias fails in namespace std?

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 16 10:50:02 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31658

            Bug ID: 31658
           Summary: Type alias fails in namespace std?
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hfinkel at anl.gov
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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 https://root.cern.ch/root/html/RStringView.h).

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?

-- 
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/20170116/001dc077/attachment-0001.html>


More information about the llvm-bugs mailing list