[cfe-dev] Keyword warnings in libc++'s type_traits and other headers
M.E. O'Neill
oneill at cs.hmc.edu
Tue Dec 24 13:04:28 PST 2013
Marshall Clow <mclow.lists at gmail.com> wrote:
> It’s also non-conforming.
>
> The user is perfectly within his rights to use _llvm_libcxx_x as an identifier or macro name (something like)
>
> #define _llvm_libcxx_x(x) do { if (x) {}} while(false);
> #include <type_traits>
>
> int main () { _llvm_libcxx_x(true); }
>
> This would fail to compile, and a user who wrote this could file a defect report against libc++ (and they would be correct!)
My point was just that using a prefix was safer than using a common word or phrase without a prefix and somehow imagining that using a double underscore will insulate you from name clashes. I don't have a problem with using __llvm_cxx_blah, _LLVM_CXX_blah, llvm_cxx__blah or just _Lblah (the last of which takes no more space than __blah if that's really a concern).
What I'd like to see is a way to avoid everyone writing a "system library" thinking they're free to use _Thread, __block, __is_pod or similar. Ideally, I'd like a way that is somewhat robust in the face of future C/C++/Objective-C language extensions.
M.E.O.
P.S. FWIW, this stack overflow post has good links to the rules about reserved identifiers in various standards (C++, C and POSIX): http://stackoverflow.com/a/228797
More information about the cfe-dev
mailing list