Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add option to show deprecated errors as warnings #248

Closed
wants to merge 2 commits into from

5 participants

Michel Fortin Leandro Lucarella Walter Bright Damian Ziemba Daniel Murphy
Michel Fortin

The new option -di treats deprecation errors as informational warnings,
just like -wi show warnings as informational messages without triggering
errors.

The deprecation option uses the same mechanism as warnings use, so the
same counter (globals.warnings) is shared for both regular and deprecation
warnings (when -di is in use). Some methods that print there own errors
now use the global function error() to print them. There is a particular
case in the Lexer where errors are not triggered but counted, in that case
the same is done with deprecation warnings, asuming it was intended
behaviour.

llucax added some commits
Leandro Lucarella llucax Add option to show deprecated errors as warnings
The new option -di treats deprecation errors as informational warnings,
just like -wi show warnings as informational messages without triggering
errors.

The deprecation option uses the same mechanism as warnings use, so the
same counter (globals.warnings) is shared for both regular and deprecation
warnings (when -di is in use). Some methods that print there own errors
now use the global function error() to print them. There is a particular
case in the Lexer where errors are not triggered but counted, in that case
the same is done with deprecation warnings, asuming it was intended
behaviour.
38a1657
Leandro Lucarella llucax Make deprecated() smarter
The deprecated() function now checks if a deprecation message should be
emitted at all, so you can now call deprecated() without checking if
global.params.deprecation is not 0 yourself. This makes code easier to
write and read.

Also restore some error messages that had "deprecated" in them but were
really plain errors (things that are not longer legal at all, not just
deprecated).
bf8a430
Brad Roberts braddr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Leandro Lucarella

I also created a bug report for this: http://d.puremagic.com/issues/show_bug.cgi?id=7041

Walter Bright
Owner

We already have so many options for deprecation and warnings, I am hard pressed to agree that adding more will help more than just add complexity.

Leandro Lucarella

I replied to the bug report because I think is better to track the issue there:
http://d.puremagic.com/issues/show_bug.cgi?id=7041

If you feel more comfortable discussing things here let me know.

Leandro Lucarella

Please see this pullrequest:
#908

It only includes the patch adding the deprecation() function. I think is good independently of the discussion about adding deprecations as warnings.

Walter Bright
Owner

I appreciate that you redid it to just add the deprecation function, but it just seems overly complex without any noticable benefit.

Damian Ziemba

What about this? It's 1 year old PR and nothing is happening here.
Also I think it was superseded by #908
@braddr @yebblies ping

Daniel Murphy
Collaborator

@nazriel Pull #908 was only part of this one, and Walter is against adding this switch. The pull itself will be much easier to review once it has been rebased.

Damian Ziemba

@yebblies yea, I am just afraid that @michelf is out (notice 0 comments about this PR, or any replies to Walter's opinion about switch). Also I think it was a reason why Leandro created #908 . So it may be a dead, rotting PR

Let's ping @michelf once again ;)

Michel Fortin

All but @nazriel's latest comment (the one with a @michelf) related to this pull request in the last 8 month never landed on my inbox. Perhaps my Github email settings are wrong. I'll look at this.

To put things in context: this pull request comes from a patch sent to the mailing list by @llucax who at the time had no Github account (look who is the author of those commits). I haven't replied here because @llucax finally got a Github account and seemed to do a good job at replying. And since I never saw Walter's last comment (because of broken email notifications) I didn't follow through either when it was left unanswered.

Assuming someone intend to salvage some remaining parts of this pull request (those not in pull #908), I think it'd be best if it was made as a separate pull request. I'll therefore close this request.

Michel Fortin michelf closed this
Leandro Lucarella

@michelf thanks for creating this pull request for me btw. I will create a new one updated, with #908 fixed and deprecated("message") already merged in I hope Walter rethink about this and we can finally have a really useful deprecated feature in the language.

Leandro Lucarella

Superseded by pull #1185 now.

AlexeyProkhin AlexeyProkhin referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2011
  1. Leandro Lucarella Michel Fortin

    Add option to show deprecated errors as warnings

    llucax authored michelf committed
    The new option -di treats deprecation errors as informational warnings,
    just like -wi show warnings as informational messages without triggering
    errors.
    
    The deprecation option uses the same mechanism as warnings use, so the
    same counter (globals.warnings) is shared for both regular and deprecation
    warnings (when -di is in use). Some methods that print there own errors
    now use the global function error() to print them. There is a particular
    case in the Lexer where errors are not triggered but counted, in that case
    the same is done with deprecation warnings, asuming it was intended
    behaviour.
  2. Leandro Lucarella Michel Fortin

    Make deprecated() smarter

    llucax authored michelf committed
    The deprecated() function now checks if a deprecation message should be
    emitted at all, so you can now call deprecated() without checking if
    global.params.deprecation is not 0 yourself. This makes code easier to
    write and read.
    
    Also restore some error messages that had "deprecated" in them but were
    really plain errors (things that are not longer legal at all, not just
    deprecated).
This page is out of date. Refresh to see the latest.
3  docs/man/man1/dmd.1
View
@@ -43,6 +43,9 @@ Write documentation file to
.IP -d
Allow deprecated features.
+.IP -di
+Show use of deprecated features as warnings.
+
.IP -debug
Compile in debug code
119 src/dsymbol.c
View
@@ -195,11 +195,8 @@ const char *Dsymbol::toPrettyChars()
return s;
}
-char *Dsymbol::locToChars()
+Loc& Dsymbol::getLoc()
{
- OutBuffer buf;
- char *p;
-
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();
@@ -207,7 +204,12 @@ char *Dsymbol::locToChars()
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
- return loc.toChars();
+ return loc;
+}
+
+char *Dsymbol::locToChars()
+{
+ return getLoc().toChars();
}
const char *Dsymbol::kind()
@@ -527,70 +529,71 @@ int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
return 0;
}
-void Dsymbol::error(const char *format, ...)
+char *Dsymbol::genMsg(const char *format)
{
- //printf("Dsymbol::error()\n");
- if (!global.gag)
+ const char* kind = this->kind();
+ const char* name;
+ size_t len = strlen(format);
+ if (!isAnonymous())
{
- char *p = locToChars();
-
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
-
- fprintf(stdmsg, "Error: ");
- if (isAnonymous())
- fprintf(stdmsg, "%s ", kind());
- else
- fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
-
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
-
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
-//halt();
+ name = toPrettyChars();
+ len += strlen(name) + 1; // +1 for a space
+ }
+ len += strlen(kind) + 1; // +1 for a space
+ char *s = (char *)mem.malloc(len + 1); // +1 for \0
+ strcpy(s, kind);
+ strcat(s, " ");
+ if (!isAnonymous()) {
+ strcat(s, name);
+ strcat(s, " ");
}
- global.errors++;
+ strcat(s, format);
+ return s;
+}
- //fatal();
+void Dsymbol::error(const char *format, ...)
+{
+ char *s = genMsg(format);
+ va_list ap;
+ va_start(ap, format);
+ ::verror(getLoc(), s, ap);
+ va_end(ap);
+ mem.free(s);
}
void Dsymbol::error(Loc loc, const char *format, ...)
{
- if (!global.gag)
- {
- char *p = loc.toChars();
- if (!*p)
- p = locToChars();
-
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
-
- fprintf(stdmsg, "Error: ");
- fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
-
- va_list ap;
- va_start(ap, format);
- vfprintf(stdmsg, format, ap);
- va_end(ap);
-
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
-//halt();
- }
+ char *s = genMsg(format);
+ va_list ap;
+ va_start(ap, format);
+ ::verror(loc, s, ap);
+ va_end(ap);
+ mem.free(s);
+}
- global.errors++;
+void Dsymbol::deprecation(const char *format, ...)
+{
+ char *s = genMsg(format);
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(getLoc(), s, ap);
+ va_end(ap);
+ mem.free(s);
+}
- //fatal();
+void Dsymbol::deprecation(Loc loc, const char *format, ...)
+{
+ char *s = genMsg(format);
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(loc, s, ap);
+ va_end(ap);
+ mem.free(s);
}
void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
{
- if (!global.params.useDeprecated && isDeprecated())
+ if (global.params.deprecation && isDeprecated())
{
// Don't complain if we're inside a deprecated symbol's scope
for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
@@ -608,7 +611,7 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
goto L1;
}
- error(loc, "is deprecated");
+ deprecation(loc, "is deprecated");
}
L1:
@@ -1109,8 +1112,8 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
{ VarDeclaration **pvar;
Expression *ce;
- if (ident == Id::length && !global.params.useDeprecated)
- error("using 'length' inside [ ] is deprecated, use '$' instead");
+ if (ident == Id::length)
+ deprecation("using 'length' inside [ ] is deprecated, use '$' instead");
L1:
4 src/dsymbol.h
View
@@ -123,11 +123,15 @@ struct Dsymbol : Object
Dsymbol();
Dsymbol(Identifier *);
char *toChars();
+ Loc& getLoc();
char *locToChars();
int equals(Object *o);
int isAnonymous();
+ char *genMsg(const char *format);
void error(Loc loc, const char *format, ...);
void error(const char *format, ...);
+ void deprecation(Loc loc, const char *format, ...);
+ void deprecation(const char *format, ...);
void checkDeprecated(Loc loc, Scope *sc);
Module *getModule();
Dsymbol *pastMixin();
35 src/expression.c
View
@@ -1058,6 +1058,17 @@ void Expression::warning(const char *format, ...)
}
}
+void Expression::deprecation(const char *format, ...)
+{
+ if (type != Type::terror)
+ {
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(loc, format, ap);
+ va_end( ap );
+ }
+}
+
void Expression::rvalue()
{
if (type && type->toBasetype()->ty == Tvoid)
@@ -4928,7 +4939,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
error("declaration %s is already defined in another scope in %s",
s->toPrettyChars(), sc->func->toChars());
}
- else if (!global.params.useDeprecated)
+ else if (global.params.deprecation)
{ // Disallow shadowing
for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
@@ -4938,7 +4949,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
(s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
s != s2)
{
- error("shadowing declaration %s is deprecated", s->toPrettyChars());
+ deprecation("shadowing declaration %s is deprecated", s->toPrettyChars());
}
}
}
@@ -5314,8 +5325,7 @@ Expression *IsExp::semantic(Scope *sc)
break;
case TOKinvariant:
- if (!global.params.useDeprecated)
- error("use of 'invariant' rather than 'immutable' is deprecated");
+ deprecation("use of 'invariant' rather than 'immutable' is deprecated");
case TOKimmutable:
if (!targ->isImmutable())
goto Lno;
@@ -8150,9 +8160,7 @@ Expression *DeleteExp::semantic(Scope *sc)
IndexExp *ae = (IndexExp *)(e1);
Type *tb1 = ae->e1->type->toBasetype();
if (tb1->ty == Taarray)
- { if (!global.params.useDeprecated)
- error("delete aa[key] deprecated, use aa.remove(key)");
- }
+ deprecation("delete aa[key] deprecated, use aa.remove(key)");
}
return this;
@@ -9303,16 +9311,9 @@ Expression *AssignExp::semantic(Scope *sc)
{
// Rewrite (a[i] = value) to (a.opIndex(i, value))
if (search_function(ad, id))
- { Expression *e = new DotIdExp(loc, ae->e1, id);
-
- if (1 || !global.params.useDeprecated)
- { error("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
- return new ErrorExp();
- }
-
- e = new CallExp(loc, e, (Expression *)ae->arguments->data[0], e2);
- e = e->semantic(sc);
- return e;
+ {
+ deprecation("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
+ return new ErrorExp();
}
}
#endif
1  src/expression.h
View
@@ -105,6 +105,7 @@ struct Expression : Object
virtual void dump(int indent);
void error(const char *format, ...);
void warning(const char *format, ...);
+ void deprecation(const char *format, ...);
virtual void rvalue();
static Expression *combine(Expression *e1, Expression *e2);
3  src/iasm.c
View
@@ -3968,8 +3968,7 @@ STATIC OPND *asm_una_exp()
// Check for offset keyword
if (asmtok->ident == Id::offset)
{
- if (!global.params.useDeprecated)
- error(asmstate.loc, "offset deprecated, use offsetof");
+ deprecation(asmstate.loc, "offset deprecated, use offsetof");
goto Loffset;
}
if (asmtok->ident == Id::offsetof)
95 src/lexer.c
View
@@ -300,48 +300,84 @@ Lexer::Lexer(Module *mod,
void Lexer::error(const char *format, ...)
{
- if (mod && !global.gag)
+ if (mod)
{
- char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
-
va_list ap;
va_start(ap, format);
- vfprintf(stdmsg, format, ap);
+ ::verror(loc, format, ap);
va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
-
if (global.errors >= 20) // moderate blizzard of cascading messages
fatal();
}
- global.errors++;
+ else
+ global.errors++;
}
void Lexer::error(Loc loc, const char *format, ...)
{
- if (mod && !global.gag)
+ if (mod)
{
- char *p = loc.toChars();
- if (*p)
- fprintf(stdmsg, "%s: ", p);
- mem.free(p);
+ va_list ap;
+ va_start(ap, format);
+ ::verror(loc, format, ap);
+ va_end(ap);
+ if (global.errors >= 20) // moderate blizzard of cascading messages
+ fatal();
+ }
+ else
+ global.errors++;
+}
+
+void Lexer::deprecation(const char *format, ...)
+{
+ if (mod)
+ {
va_list ap;
va_start(ap, format);
- vfprintf(stdmsg, format, ap);
+ ::vdeprecation(loc, format, ap);
va_end(ap);
- fprintf(stdmsg, "\n");
- fflush(stdmsg);
+ if (global.params.deprecation == 2 &&
+ global.warnings >= 20) // moderate blizzard of cascading messages
+ fatal();
+ else if (global.params.deprecation == 1 &&
+ global.errors >= 20) // moderate blizzard of cascading messages
+ fatal();
+ }
+ else
+ {
+ if (global.params.deprecation == 2)
+ global.warnings++;
+ else
+ global.errors++;
+ }
+}
+
+void Lexer::deprecation(Loc loc, const char *format, ...)
+{
+ if (mod)
+ {
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(loc, format, ap);
+ va_end(ap);
- if (global.errors >= 20) // moderate blizzard of cascading messages
+ if (global.params.deprecation == 2 &&
+ global.warnings >= 20) // moderate blizzard of cascading messages
+ fatal();
+ else if (global.params.deprecation == 1 &&
+ global.errors >= 20) // moderate blizzard of cascading messages
fatal();
}
- global.errors++;
+ else
+ {
+ if (global.params.deprecation == 1)
+ global.warnings++;
+ else
+ global.errors++;
+ }
}
TOK Lexer::nextToken()
@@ -624,8 +660,7 @@ void Lexer::scan(Token *t)
t->postfix = 0;
t->value = TOKstring;
#if DMDV2
- if (!global.params.useDeprecated)
- error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
+ deprecation("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
#endif
return;
}
@@ -2274,8 +2309,7 @@ TOK Lexer::number(Token *t)
goto L1;
case 'l':
- if (1 || !global.params.useDeprecated)
- error("'l' suffix is deprecated, use 'L' instead");
+ error("'l' suffix is no longer legal, use 'L' instead");
case 'L':
f = FLAGS_long;
L1:
@@ -2290,8 +2324,8 @@ TOK Lexer::number(Token *t)
break;
}
- if (state == STATE_octal && n >= 8 && !global.params.useDeprecated)
- error("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
+ if (state == STATE_octal && n >= 8)
+ deprecation("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
n, p - psuffix, psuffix, n, p - psuffix, psuffix);
switch (flags)
@@ -2522,8 +2556,7 @@ __body
break;
case 'l':
- if (!global.params.useDeprecated)
- error("'l' suffix is deprecated, use 'L' instead");
+ error("'l' suffix is no longer legal, use 'L' instead");
case 'L':
result = TOKfloat80v;
p++;
@@ -2531,8 +2564,8 @@ __body
}
if (*p == 'i' || *p == 'I')
{
- if (!global.params.useDeprecated && *p == 'I')
- error("'I' suffix is deprecated, use 'i' instead");
+ if (*p == 'I')
+ deprecation("'I' suffix is deprecated, use 'i' instead");
p++;
switch (result)
{
2  src/lexer.h
View
@@ -302,6 +302,8 @@ struct Lexer
TOK inreal(Token *t);
void error(const char *format, ...);
void error(Loc loc, const char *format, ...);
+ void deprecation(const char *format, ...);
+ void deprecation(Loc loc, const char *format, ...);
void pragma();
unsigned decodeUTF();
void getDocComment(Token *t, unsigned lineComment);
31 src/mars.c
View
@@ -155,6 +155,14 @@ void warning(Loc loc, const char *format, ...)
va_end( ap );
}
+void deprecation(Loc loc, const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ vdeprecation(loc, format, ap);
+ va_end( ap );
+}
+
void verror(Loc loc, const char *format, va_list ap)
{
if (!global.gag)
@@ -208,6 +216,23 @@ void vwarning(Loc loc, const char *format, va_list ap)
}
}
+void vdeprecation(Loc loc, const char *format, va_list ap)
+{
+ char oldw;
+ switch (global.params.deprecation)
+ {
+ case 2:
+ oldw = global.params.warnings;
+ global.params.warnings = 2; // activate informational warnings temporarly
+ vwarning(loc, format, ap);
+ global.params.warnings = oldw;
+ break;
+ case 1:
+ verror(loc, format, ap);
+ break;
+ }
+}
+
/***************************************
* Call this after printing out fatal error messages to clean up and exit
* the compiler.
@@ -260,6 +285,7 @@ Usage:\n\
-Dddocdir write documentation file to docdir directory\n\
-Dffilename write documentation file to filename\n\
-d allow deprecated features\n\
+ -di show use of deprecated features as warnings\n\
-debug compile in debug code\n\
-debug=level compile in debug code <= level\n\
-debug=ident compile in debug code identified by ident\n\
@@ -359,6 +385,7 @@ int main(int argc, char *argv[])
global.params.obj = 1;
global.params.Dversion = 2;
global.params.quiet = 1;
+ global.params.deprecation = 1; // deprecated features are errors
global.params.linkswitches = new Array();
global.params.libfiles = new Array();
@@ -443,7 +470,9 @@ int main(int argc, char *argv[])
if (*p == '-')
{
if (strcmp(p + 1, "d") == 0)
- global.params.useDeprecated = 1;
+ global.params.deprecation = 0;
+ else if (strcmp(p + 1, "di") == 0)
+ global.params.deprecation = 2;
else if (strcmp(p + 1, "c") == 0)
global.params.link = 0;
else if (strcmp(p + 1, "cov") == 0)
13 src/mars.h
View
@@ -146,7 +146,9 @@ struct Param
char isOPenBSD; // generate code for OpenBSD
char isSolaris; // generate code for Solaris
char scheduler; // which scheduler to use
- char useDeprecated; // allow use of deprecated features
+ char deprecation; // 0: sillently allow use of deprecated features
+ // 1: use of deprecated features as errors
+ // 2: informational warnings (no errors)
char useAssert; // generate runtime code for assert()'s
char useInvariants; // generate class invariant checks
char useIn; // generate precondition checks
@@ -247,9 +249,10 @@ struct Global
const char *version;
Param params;
- unsigned errors; // number of errors reported so far
- unsigned warnings; // number of warnings reported so far
- unsigned gag; // !=0 means gag reporting of errors & warnings
+ unsigned errors; // number of errors reported so far
+ unsigned warnings; // number of warnings reported so far
+ unsigned deprecations; // number of deprecations reported so far
+ unsigned gag; // !=0 means gag reporting of errors & warnings
Global();
};
@@ -389,8 +392,10 @@ typedef uint64_t StorageClass;
void warning(Loc loc, const char *format, ...);
void error(Loc loc, const char *format, ...);
+void deprecation(Loc loc, const char *format, ...);
void verror(Loc loc, const char *format, va_list);
void vwarning(Loc loc, const char *format, va_list);
+void vdeprecation(Loc loc, const char *format, va_list);
void fatal();
void err_nomem();
int runLINK();
4 src/module.c
View
@@ -128,8 +128,8 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
if (srcfilename->equalsExt("html") ||
srcfilename->equalsExt("htm") ||
srcfilename->equalsExt("xhtml"))
- { if (!global.params.useDeprecated)
- error("html source files is deprecated %s", srcfilename->toChars());
+ {
+ deprecation("html source files is deprecated %s", srcfilename->toChars());
isHtml = 1;
}
else
14 src/mtype.c
View
@@ -56,7 +56,7 @@ FuncDeclaration *hasThis(Scope *sc);
#define LOGDEFAULTINIT 0 // log ::defaultInit()
// Allow implicit conversion of T[] to T*
-#define IMPLICIT_ARRAY_TO_PTR global.params.useDeprecated
+#define IMPLICIT_ARRAY_TO_PTR (global.params.deprecation != 1)
/* These have default values for 32 bit code, they get
* adjusted for 64 bit code.
@@ -1699,8 +1699,7 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
}
else if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(NULL);
}
else if (ident == Id::init)
@@ -1768,8 +1767,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
if (ident == Id::offset)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".offset deprecated, use .offsetof");
+ deprecation(e->loc, ".offset deprecated, use .offsetof");
goto Loffset;
}
else if (ident == Id::offsetof)
@@ -1818,8 +1816,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
}
if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(sc);
}
else if (ident == Id::stringof)
@@ -7542,8 +7539,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (ident == Id::typeinfo)
{
- if (!global.params.useDeprecated)
- error(e->loc, ".typeinfo deprecated, use typeid(type)");
+ deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
return getTypeInfo(sc);
}
if (ident == Id::outer && sym->vthis)
17 src/parse.c
View
@@ -668,8 +668,7 @@ StorageClass Parser::parsePostfix()
{
case TOKconst: stc |= STCconst; break;
case TOKinvariant:
- if (!global.params.useDeprecated)
- error("use of 'invariant' rather than 'immutable' is deprecated");
+ deprecation("use of 'invariant' rather than 'immutable' is deprecated");
case TOKimmutable: stc |= STCimmutable; break;
case TOKshared: stc |= STCshared; break;
case TOKwild: stc |= STCwild; break;
@@ -2337,8 +2336,7 @@ Type *Parser::parseBasicType()
break;
case TOKinvariant:
- if (!global.params.useDeprecated)
- error("use of 'invariant' rather than 'immutable' is deprecated");
+ deprecation("use of 'invariant' rather than 'immutable' is deprecated");
case TOKimmutable:
// invariant(type)
nextToken();
@@ -2503,10 +2501,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
* although the D style would be:
* int[]*[3] ident
*/
- if (!global.params.useDeprecated)
- {
- error("C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers");
- }
+ deprecation("C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers");
nextToken();
ts = parseDeclarator(t, pident);
check(TOKrparen);
@@ -3792,8 +3787,7 @@ Statement *Parser::parseStatement(int flags)
arg = new Parameter(0, NULL, token.ident, NULL);
nextToken();
nextToken();
- if (1 || !global.params.useDeprecated)
- error("if (v; e) is deprecated, use if (auto v = e)");
+ error("if (v; e) is no longer legal, use if (auto v = e)");
}
}
@@ -4159,8 +4153,7 @@ Statement *Parser::parseStatement(int flags)
nextToken();
s = parseStatement(PSsemi | PScurlyscope);
#if DMDV2
- if (!global.params.useDeprecated)
- error("volatile statements deprecated; used synchronized statements instead");
+ deprecation("volatile statements deprecated; used synchronized statements instead");
#endif
s = new VolatileStatement(loc, s);
break;
11 src/statement.c
View
@@ -116,6 +116,14 @@ void Statement::warning(const char *format, ...)
va_end( ap );
}
+void Statement::deprecation(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ ::vdeprecation(loc, format, ap);
+ va_end( ap );
+}
+
int Statement::hasBreak()
{
//printf("Statement::hasBreak()\n");
@@ -2858,8 +2866,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
if (!sc->sw->sdefault && !isFinal)
{ hasNoDefault = 1;
- if (!global.params.useDeprecated)
- error("non-final switch statement without a default is deprecated");
+ deprecation("non-final switch statement without a default is deprecated");
// Generate runtime error if the default is hit
Statements *a = new Statements();
1  src/statement.h
View
@@ -92,6 +92,7 @@ struct Statement : Object
void error(const char *format, ...);
void warning(const char *format, ...);
+ void deprecation(const char *format, ...);
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int incontract;
virtual ScopeStatement *isScopeStatement() { return NULL; }
6 src/toobj.c
View
@@ -810,13 +810,13 @@ void ClassDeclaration::toObjFile(int multiobj)
continue;
if (fd->leastAsSpecialized(fd2) || fd2->leastAsSpecialized(fd))
{
- if (!global.params.useDeprecated)
+ if (global.params.deprecation)
{
TypeFunction *tf = (TypeFunction *)fd->type;
if (tf->ty == Tfunction)
- error("use of %s%s hidden by %s is deprecated\n", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars());
+ deprecation("use of %s%s hidden by %s is deprecated\n", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars());
else
- error("use of %s hidden by %s is deprecated\n", fd->toPrettyChars(), toChars());
+ deprecation("use of %s hidden by %s is deprecated\n", fd->toPrettyChars(), toChars());
}
s = rtlsym[RTLSYM_DHIDDENFUNC];
break;
Something went wrong with that request. Please try again.