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

Jim Porter via cfe-users cfe-users at lists.llvm.org
Mon Feb 29 12:07:51 PST 2016


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





More information about the cfe-users mailing list