[cfe-users] Anyway to prevent this code from compiling?

don hinton via cfe-users cfe-users at lists.llvm.org
Tue Mar 1 05:57:25 PST 2016

That's a good point.  Since mutex is a new c++11 feature, why is it
injected into the std namespace when not compiling with c++11.  I looked at
the mutex header, and it doesn't test current value of __cplusplus.

Should it?

On Mon, Feb 29, 2016 at 3:07 PM, Jim Porter via cfe-users <
cfe-users at lists.llvm.org> wrote:

> On 2/29/2016 12:15 PM, Brian Cole via cfe-users wrote:
>> Was hoping for something that would be C++03 compatible as well since we
>> still have C++03 compilers to target as well.
> If you're #including <mutex>, haven't you locked yourself into C++11 (or
> better) anyway? In that case, you should use curly braces for your
> initializer (or at least stop saying `using namespace std;`).
> For existing code where `mutex` is a global variable, you'll be fine. If
> you add
>   #include <mutex>
>   using namespace std;
> to existing code, you'll get a compiler error because the name `mutex` is
> now ambiguous.
> If you wanted to warn about this in *all* cases, you'd need an additional
> warning to detect function declarations in local scope, since that's what
> C++ would treat this as. Clang doesn't have such a warning, but perhaps you
> could convince someone to add it.
> - Jim
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20160301/25884ed5/attachment.html>

More information about the cfe-users mailing list