[PATCH] Deprecated attribute on namespaces
Richard Smith
richard at metafoo.co.uk
Thu Nov 13 18:13:08 PST 2014
On Sat, Nov 8, 2014 at 4:05 PM, Aaron Ballman <aaron at aaronballman.com>
wrote:
> C++1z now allows attributes on namespace and enumerators. We already
> supported deprecated enumerators, but we do not support namespaces.
> This patch addresses that.
>
> A few notes:
>
> It was decided that the deprecated attribute only applies to things
> with names (this makes reporting diagnostics a bit more sane), so this
> patch disallows deprecating an anonymous namespace.
>
> Since the declaration context can now cause deprecations, this
> requires updating some other test cases.
This wasn't the intention when this was discussed with EWG; the idea was
that using a deprecated name would result in a warning, but merely naming
something that's in a deprecated context would not. So:
namespace [[deprecated]] N {
int x;
int y = x; // no warning
int f();
}
using N::x; // warning
int z1 = x; // no warning
using namespace N; // warning
int z2 = y; // no warning
// no warnings from this function
int N::f() {
return y;
}
This allows, for instance:
namespace OldNamespace {
// old stuff
}
namespace NewNamespace {
using OldNamespace::a;
using OldNamespace::b;
namespace C = OldNamespace::Inner;
}
namespace [[deprecated("use NewNamespace instead")]] OldNamespace {}
On the Clang side, the idea would be to check declarations that get used as
part of a NestedNameSpecifier to see if they're deprecated, rather than
recursing through parents to see if each used declaration is in a
deprecated context.
Several of them now receive
> two notes -- one for the declaration of a variable of enumerator type,
> another for the use of the enumerator.
>
> There are still improvements to be made for situations where a class
> is effectively providing a namespace (static members, inner types,
> etc).
>
> ~Aaron
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141113/3f872090/attachment.html>
More information about the cfe-commits
mailing list