[cfe-dev] [libc++] Is namespace "index" a special kind of a namespace in libc++?

John McCall via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 29 14:38:02 PDT 2017


> On Oct 29, 2017, at 4:14 PM, Richard Smith via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> There is a ::index function in strings.h on some platforms that might be leaking into <algorithm>.

And I would add to this that I've definitely seen Clang give pretty bad diagnostics when it hits this kind of ambiguity.

John.

> 
> On 29 Oct 2017 13:10, "Klemen Forstnerič via cfe-dev" <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> Hi libc++ developers,
> 
> I'm having a problem compiling the following code:
> 
> Header (index.hpp):
> 
> #ifndef INDEX_HPP_
> #define INDEX_HPP_
> 
> #include <algorithm>
> 
> namespace index {
> 
> class Index {
>  public:
>   Index();
> };
> 
> }
> 
> #endif // INDEX_HPP_
> 
> Source (index.cpp):
> 
> #include "index.hpp"
> 
> namespace index {
> 
> Index::Index() {
> }
> 
> }
> 
> These are the errors I get:
> 
> index.cpp:5:1: error: use of undeclared identifier 'Index'; did you mean '::index::Index'?
> Index::Index() {
> ^~~~~
> ::index::Index
> ./index.hpp:8:7: note: '::index::Index' declared here
> class Index {
>       ^
> index.cpp:5:8: error: cannot define or redeclare 'Index' here because namespace 'index' does not enclose namespace 'Index'
> Index::Index() {
> ~~~~~~~^
> 2 errors generated.
> 
> This is my compile command:
> clang++ --stdlib=libc++ index.cpp
> 
> clang version:
> clang version 5.0.0 (tags/RELEASE_500/final)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/local/bin
> 
> libc++ version is today's trunk
> 
> System: Linux trusty64 3.16.0-55-generic #74~14.04.1-Ubuntu SMP Tue Nov 17 10:15:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
> 
> 
> If I don't include <algorithm> or if I change the name of the namespace to something other than "index", the code compiles.
> 
> Is this a libc++ bug?
> 
> Cheers,
> Klemen
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171029/0bf6d26a/attachment.html>


More information about the cfe-dev mailing list