From 7a103daef78a8f9fc9b2af7c28123f25e8fa7163 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 7 Jan 2021 22:00:24 +0100 Subject: d: Support deprecated, @disable, and user-defined attributes on enum members Reviewed-on: https://github.com/dlang/dmd/pull/12108 gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 9bba772fa. --- gcc/d/dmd/declaration.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'gcc/d/dmd/declaration.c') diff --git a/gcc/d/dmd/declaration.c b/gcc/d/dmd/declaration.c index f196bc8..72a07d9b8 100644 --- a/gcc/d/dmd/declaration.c +++ b/gcc/d/dmd/declaration.c @@ -155,6 +155,51 @@ int Declaration::checkModify(Loc loc, Scope *sc, Type *, Expression *e1, int fla return 1; } +/** + * Issue an error if an attempt to call a disabled method is made + * + * If the declaration is disabled but inside a disabled function, + * returns `true` but do not issue an error message. + * + * Params: + * loc = Location information of the call + * sc = Scope in which the call occurs + * isAliasedDeclaration = if `true` searches overload set + * + * Returns: + * `true` if this `Declaration` is `@disable`d, `false` otherwise. + */ +bool Declaration::checkDisabled(Loc loc, Scope *sc, bool isAliasedDeclaration) +{ + if (!(storage_class & STCdisable)) + return false; + + if (sc->func && (sc->func->storage_class & STCdisable)) + return true; + + Dsymbol *p = toParent(); + if (p && isPostBlitDeclaration()) + { + p->error(loc, "is not copyable because it is annotated with `@disable`"); + return true; + } + + // if the function is @disabled, maybe there + // is an overload in the overload set that isn't + if (isAliasedDeclaration) + { + FuncDeclaration *fd = isFuncDeclaration(); + if (fd) + { + for (FuncDeclaration *ovl = fd; ovl; ovl = (FuncDeclaration *)ovl->overnext) + if (!(ovl->storage_class & STCdisable)) + return false; + } + } + error(loc, "cannot be used because it is annotated with `@disable`"); + return true; +} + Dsymbol *Declaration::search(const Loc &loc, Identifier *ident, int flags) { Dsymbol *s = Dsymbol::search(loc, ident, flags); -- cgit v1.1