[vlc-devel] [vlc-commits] Remove using namespace std; from C++ code

Hugo Beauzée-Luyssen hugo at beauzee.fr
Mon Jun 22 17:42:59 CEST 2015

On 22/06/2015 16:46, Rémi Denis-Courmont wrote:
> Le 2015-06-22 17:44, Tristan Matthews a écrit :
>>> If we need to depend on a library that has "using namespace std;"
>>> in its public header, then what?
>> Not that I disagree with earlier points, but said library would be
>> acting crazy. Putting "using namespace std" in a header is extremely
>> bad form, especially in a librarys public header.
> But that works the other way too: LibVLC cannot depend on the external
> plugins using or not using the std namespace. It must work in both cases.

The issue originally rise because we use atomic_{load|store|init} along 
with std::atomic_* types, which are not specialization of std::atomic<T>.

In order to keep the same atomic code, we need the atomic types to be 
part of the global namespace.

In order to be able to use atomic_load & co (at least on GCC, I haven't 
checked clang), we need to specify ourselves that atomic_int is an 
explicit specialization of std::atomic<T>, rather than relying on 
std::atomic_int, which is a specialization std::atomic_base.

Doing so with a using namespace std; will cause 2 different types with 
the same name to appear in the global namespace, thus causing the build 
to fail.
I don't really have any other proposal to fix the builds, which are not 
involving rolling back to C++99, requiring GCC 5.x, or using atomic 
types for c++, and atomic functions for C.

That issue aside, I honestly think it's a better idea not to use "using 
namespace std;"


Hugo Beauzée-Luyssen

More information about the vlc-devel mailing list