[cfe-users] Anyway to prevent this code from compiling?
don hinton via cfe-users
cfe-users at lists.llvm.org
Tue Mar 1 09:04:23 PST 2016
Just looked online and stdlibc++ has this at the top the mutex header:
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
Shouldn't we perform the same sort of check?
On Tue, Mar 1, 2016 at 8:57 AM, don hinton <hintonda at gmail.com> wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-users