Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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.

added some commits
Leandro Lucarella 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 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

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

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 michelf closed this
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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 2 authors.

Jul 13, 2011
Leandro Lucarella 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 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
This page is out of date. Refresh to see the latest.
3  docs/man/man1/dmd.1
@@ -43,6 +43,9 @@ Write documentation file to
43 43
 .IP -d
44 44
 Allow deprecated features.
45 45
 
  46
+.IP -di
  47
+Show use of deprecated features as warnings.
  48
+
46 49
 .IP -debug
47 50
 Compile in debug code
48 51
 
119  src/dsymbol.c
@@ -195,11 +195,8 @@ const char *Dsymbol::toPrettyChars()
195 195
     return s;
196 196
 }
197 197
 
198  
-char *Dsymbol::locToChars()
  198
+Loc& Dsymbol::getLoc()
199 199
 {
200  
-    OutBuffer buf;
201  
-    char *p;
202  
-
203 200
     if (!loc.filename)  // avoid bug 5861.
204 201
     {
205 202
         Module *m = getModule();
@@ -207,7 +204,12 @@ char *Dsymbol::locToChars()
207 204
         if (m && m->srcfile)
208 205
             loc.filename = m->srcfile->toChars();
209 206
     }
210  
-    return loc.toChars();
  207
+    return loc;
  208
+}
  209
+
  210
+char *Dsymbol::locToChars()
  211
+{
  212
+    return getLoc().toChars();
211 213
 }
212 214
 
213 215
 const char *Dsymbol::kind()
@@ -527,70 +529,71 @@ int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
527 529
     return 0;
528 530
 }
529 531
 
530  
-void Dsymbol::error(const char *format, ...)
  532
+char *Dsymbol::genMsg(const char *format)
531 533
 {
532  
-    //printf("Dsymbol::error()\n");
533  
-    if (!global.gag)
  534
+    const char* kind = this->kind();
  535
+    const char* name;
  536
+    size_t len = strlen(format);
  537
+    if (!isAnonymous())
534 538
     {
535  
-        char *p = locToChars();
536  
-
537  
-        if (*p)
538  
-            fprintf(stdmsg, "%s: ", p);
539  
-        mem.free(p);
540  
-
541  
-        fprintf(stdmsg, "Error: ");
542  
-        if (isAnonymous())
543  
-            fprintf(stdmsg, "%s ", kind());
544  
-        else
545  
-            fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
546  
-
547  
-        va_list ap;
548  
-        va_start(ap, format);
549  
-        vfprintf(stdmsg, format, ap);
550  
-        va_end(ap);
551  
-
552  
-        fprintf(stdmsg, "\n");
553  
-        fflush(stdmsg);
554  
-//halt();
  539
+        name = toPrettyChars();
  540
+        len += strlen(name) + 1; // +1 for a space
  541
+    }
  542
+    len += strlen(kind) + 1; // +1 for a space
  543
+    char *s = (char *)mem.malloc(len + 1); // +1 for \0
  544
+    strcpy(s, kind);
  545
+    strcat(s, " ");
  546
+    if (!isAnonymous()) {
  547
+        strcat(s, name);
  548
+        strcat(s, " ");
555 549
     }
556  
-    global.errors++;
  550
+    strcat(s, format);
  551
+    return s;
  552
+}
557 553
 
558  
-    //fatal();
  554
+void Dsymbol::error(const char *format, ...)
  555
+{
  556
+    char *s = genMsg(format);
  557
+    va_list ap;
  558
+    va_start(ap, format);
  559
+    ::verror(getLoc(), s, ap);
  560
+    va_end(ap);
  561
+    mem.free(s);
559 562
 }
560 563
 
561 564
 void Dsymbol::error(Loc loc, const char *format, ...)
562 565
 {
563  
-    if (!global.gag)
564  
-    {
565  
-        char *p = loc.toChars();
566  
-        if (!*p)
567  
-            p = locToChars();
568  
-
569  
-        if (*p)
570  
-            fprintf(stdmsg, "%s: ", p);
571  
-        mem.free(p);
572  
-
573  
-        fprintf(stdmsg, "Error: ");
574  
-        fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
575  
-
576  
-        va_list ap;
577  
-        va_start(ap, format);
578  
-        vfprintf(stdmsg, format, ap);
579  
-        va_end(ap);
580  
-
581  
-        fprintf(stdmsg, "\n");
582  
-        fflush(stdmsg);
583  
-//halt();
584  
-    }
  566
+    char *s = genMsg(format);
  567
+    va_list ap;
  568
+    va_start(ap, format);
  569
+    ::verror(loc, s, ap);
  570
+    va_end(ap);
  571
+    mem.free(s);
  572
+}
585 573
 
586  
-    global.errors++;
  574
+void Dsymbol::deprecation(const char *format, ...)
  575
+{
  576
+    char *s = genMsg(format);
  577
+    va_list ap;
  578
+    va_start(ap, format);
  579
+    ::vdeprecation(getLoc(), s, ap);
  580
+    va_end(ap);
  581
+    mem.free(s);
  582
+}
587 583
 
588  
-    //fatal();
  584
+void Dsymbol::deprecation(Loc loc, const char *format, ...)
  585
+{
  586
+    char *s = genMsg(format);
  587
+    va_list ap;
  588
+    va_start(ap, format);
  589
+    ::vdeprecation(loc, s, ap);
  590
+    va_end(ap);
  591
+    mem.free(s);
589 592
 }
590 593
 
591 594
 void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
592 595
 {
593  
-    if (!global.params.useDeprecated && isDeprecated())
  596
+    if (global.params.deprecation && isDeprecated())
594 597
     {
595 598
         // Don't complain if we're inside a deprecated symbol's scope
596 599
         for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
@@ -608,7 +611,7 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
608 611
                 goto L1;
609 612
         }
610 613
 
611  
-        error(loc, "is deprecated");
  614
+        deprecation(loc, "is deprecated");
612 615
     }
613 616
 
614 617
   L1:
@@ -1109,8 +1112,8 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
1109 1112
     {   VarDeclaration **pvar;
1110 1113
         Expression *ce;
1111 1114
 
1112  
-        if (ident == Id::length && !global.params.useDeprecated)
1113  
-            error("using 'length' inside [ ] is deprecated, use '$' instead");
  1115
+        if (ident == Id::length)
  1116
+            deprecation("using 'length' inside [ ] is deprecated, use '$' instead");
1114 1117
 
1115 1118
     L1:
1116 1119
 
4  src/dsymbol.h
@@ -123,11 +123,15 @@ struct Dsymbol : Object
123 123
     Dsymbol();
124 124
     Dsymbol(Identifier *);
125 125
     char *toChars();
  126
+    Loc& getLoc();
126 127
     char *locToChars();
127 128
     int equals(Object *o);
128 129
     int isAnonymous();
  130
+    char *genMsg(const char *format);
129 131
     void error(Loc loc, const char *format, ...);
130 132
     void error(const char *format, ...);
  133
+    void deprecation(Loc loc, const char *format, ...);
  134
+    void deprecation(const char *format, ...);
131 135
     void checkDeprecated(Loc loc, Scope *sc);
132 136
     Module *getModule();
133 137
     Dsymbol *pastMixin();
35  src/expression.c
@@ -1058,6 +1058,17 @@ void Expression::warning(const char *format, ...)
1058 1058
     }
1059 1059
 }
1060 1060
 
  1061
+void Expression::deprecation(const char *format, ...)
  1062
+{
  1063
+    if (type != Type::terror)
  1064
+    {
  1065
+        va_list ap;
  1066
+        va_start(ap, format);
  1067
+        ::vdeprecation(loc, format, ap);
  1068
+        va_end( ap );
  1069
+    }
  1070
+}
  1071
+
1061 1072
 void Expression::rvalue()
1062 1073
 {
1063 1074
     if (type && type->toBasetype()->ty == Tvoid)
@@ -4928,7 +4939,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
4928 4939
                 error("declaration %s is already defined in another scope in %s",
4929 4940
                     s->toPrettyChars(), sc->func->toChars());
4930 4941
             }
4931  
-            else if (!global.params.useDeprecated)
  4942
+            else if (global.params.deprecation)
4932 4943
             {   // Disallow shadowing
4933 4944
 
4934 4945
                 for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
@@ -4938,7 +4949,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
4938 4949
                         (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
4939 4950
                         s != s2)
4940 4951
                     {
4941  
-                        error("shadowing declaration %s is deprecated", s->toPrettyChars());
  4952
+                        deprecation("shadowing declaration %s is deprecated", s->toPrettyChars());
4942 4953
                     }
4943 4954
                 }
4944 4955
             }
@@ -5314,8 +5325,7 @@ Expression *IsExp::semantic(Scope *sc)
5314 5325
                 break;
5315 5326
 
5316 5327
             case TOKinvariant:
5317  
-                if (!global.params.useDeprecated)
5318  
-                    error("use of 'invariant' rather than 'immutable' is deprecated");
  5328
+                deprecation("use of 'invariant' rather than 'immutable' is deprecated");
5319 5329
             case TOKimmutable:
5320 5330
                 if (!targ->isImmutable())
5321 5331
                     goto Lno;
@@ -8150,9 +8160,7 @@ Expression *DeleteExp::semantic(Scope *sc)
8150 8160
         IndexExp *ae = (IndexExp *)(e1);
8151 8161
         Type *tb1 = ae->e1->type->toBasetype();
8152 8162
         if (tb1->ty == Taarray)
8153  
-        {   if (!global.params.useDeprecated)
8154  
-                error("delete aa[key] deprecated, use aa.remove(key)");
8155  
-        }
  8163
+            deprecation("delete aa[key] deprecated, use aa.remove(key)");
8156 8164
     }
8157 8165
 
8158 8166
     return this;
@@ -9303,16 +9311,9 @@ Expression *AssignExp::semantic(Scope *sc)
9303 9311
             {
9304 9312
                 // Rewrite (a[i] = value) to (a.opIndex(i, value))
9305 9313
                 if (search_function(ad, id))
9306  
-                {   Expression *e = new DotIdExp(loc, ae->e1, id);
9307  
-
9308  
-                    if (1 || !global.params.useDeprecated)
9309  
-                    {   error("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
9310  
-                        return new ErrorExp();
9311  
-                    }
9312  
-
9313  
-                    e = new CallExp(loc, e, (Expression *)ae->arguments->data[0], e2);
9314  
-                    e = e->semantic(sc);
9315  
-                    return e;
  9314
+                {
  9315
+                    deprecation("operator [] assignment overload with opIndex(i, value) illegal, use opIndexAssign(value, i)");
  9316
+                    return new ErrorExp();
9316 9317
                 }
9317 9318
             }
9318 9319
 #endif
1  src/expression.h
@@ -105,6 +105,7 @@ struct Expression : Object
105 105
     virtual void dump(int indent);
106 106
     void error(const char *format, ...);
107 107
     void warning(const char *format, ...);
  108
+    void deprecation(const char *format, ...);
108 109
     virtual void rvalue();
109 110
 
110 111
     static Expression *combine(Expression *e1, Expression *e2);
3  src/iasm.c
@@ -3968,8 +3968,7 @@ STATIC OPND *asm_una_exp()
3968 3968
                     // Check for offset keyword
3969 3969
                     if (asmtok->ident == Id::offset)
3970 3970
                     {
3971  
-                        if (!global.params.useDeprecated)
3972  
-                            error(asmstate.loc, "offset deprecated, use offsetof");
  3971
+                        deprecation(asmstate.loc, "offset deprecated, use offsetof");
3973 3972
                         goto Loffset;
3974 3973
                     }
3975 3974
                     if (asmtok->ident == Id::offsetof)
95  src/lexer.c
@@ -300,48 +300,84 @@ Lexer::Lexer(Module *mod,
300 300
 
301 301
 void Lexer::error(const char *format, ...)
302 302
 {
303  
-    if (mod && !global.gag)
  303
+    if (mod)
304 304
     {
305  
-        char *p = loc.toChars();
306  
-        if (*p)
307  
-            fprintf(stdmsg, "%s: ", p);
308  
-        mem.free(p);
309  
-
310 305
         va_list ap;
311 306
         va_start(ap, format);
312  
-        vfprintf(stdmsg, format, ap);
  307
+        ::verror(loc, format, ap);
313 308
         va_end(ap);
314 309
 
315  
-        fprintf(stdmsg, "\n");
316  
-        fflush(stdmsg);
317  
-
318 310
         if (global.errors >= 20)        // moderate blizzard of cascading messages
319 311
             fatal();
320 312
     }
321  
-    global.errors++;
  313
+    else
  314
+        global.errors++;
322 315
 }
323 316
 
324 317
 void Lexer::error(Loc loc, const char *format, ...)
325 318
 {
326  
-    if (mod && !global.gag)
  319
+    if (mod)
327 320
     {
328  
-        char *p = loc.toChars();
329  
-        if (*p)
330  
-            fprintf(stdmsg, "%s: ", p);
331  
-        mem.free(p);
  321
+        va_list ap;
  322
+        va_start(ap, format);
  323
+        ::verror(loc, format, ap);
  324
+        va_end(ap);
332 325
 
  326
+        if (global.errors >= 20)        // moderate blizzard of cascading messages
  327
+            fatal();
  328
+    }
  329
+    else
  330
+        global.errors++;
  331
+}
  332
+
  333
+void Lexer::deprecation(const char *format, ...)
  334
+{
  335
+    if (mod)
  336
+    {
333 337
         va_list ap;
334 338
         va_start(ap, format);
335  
-        vfprintf(stdmsg, format, ap);
  339
+        ::vdeprecation(loc, format, ap);
336 340
         va_end(ap);
337 341
 
338  
-        fprintf(stdmsg, "\n");
339  
-        fflush(stdmsg);
  342
+        if (global.params.deprecation == 2 &&
  343
+                global.warnings >= 20)  // moderate blizzard of cascading messages
  344
+            fatal();
  345
+        else if (global.params.deprecation == 1 &&
  346
+                global.errors >= 20)    // moderate blizzard of cascading messages
  347
+            fatal();
  348
+    }
  349
+    else
  350
+    {
  351
+        if (global.params.deprecation == 2)
  352
+            global.warnings++;
  353
+        else
  354
+            global.errors++;
  355
+    }
  356
+}
  357
+
  358
+void Lexer::deprecation(Loc loc, const char *format, ...)
  359
+{
  360
+    if (mod)
  361
+    {
  362
+        va_list ap;
  363
+        va_start(ap, format);
  364
+        ::vdeprecation(loc, format, ap);
  365
+        va_end(ap);
340 366
 
341  
-        if (global.errors >= 20)        // moderate blizzard of cascading messages
  367
+        if (global.params.deprecation == 2 &&
  368
+                global.warnings >= 20)  // moderate blizzard of cascading messages
  369
+            fatal();
  370
+        else if (global.params.deprecation == 1 &&
  371
+                global.errors >= 20)    // moderate blizzard of cascading messages
342 372
             fatal();
343 373
     }
344  
-    global.errors++;
  374
+    else
  375
+    {
  376
+        if (global.params.deprecation == 1)
  377
+            global.warnings++;
  378
+        else
  379
+            global.errors++;
  380
+    }
345 381
 }
346 382
 
347 383
 TOK Lexer::nextToken()
@@ -624,8 +660,7 @@ void Lexer::scan(Token *t)
624 660
                 t->postfix = 0;
625 661
                 t->value = TOKstring;
626 662
 #if DMDV2
627  
-                if (!global.params.useDeprecated)
628  
-                    error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
  663
+                deprecation("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
629 664
 #endif
630 665
                 return;
631 666
             }
@@ -2274,8 +2309,7 @@ TOK Lexer::number(Token *t)
2274 2309
                 goto L1;
2275 2310
 
2276 2311
             case 'l':
2277  
-                if (1 || !global.params.useDeprecated)
2278  
-                    error("'l' suffix is deprecated, use 'L' instead");
  2312
+                error("'l' suffix is no longer legal, use 'L' instead");
2279 2313
             case 'L':
2280 2314
                 f = FLAGS_long;
2281 2315
             L1:
@@ -2290,8 +2324,8 @@ TOK Lexer::number(Token *t)
2290 2324
         break;
2291 2325
     }
2292 2326
 
2293  
-    if (state == STATE_octal && n >= 8 && !global.params.useDeprecated)
2294  
-        error("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
  2327
+    if (state == STATE_octal && n >= 8)
  2328
+        deprecation("octal literals 0%llo%.*s are deprecated, use std.conv.octal!%llo%.*s instead",
2295 2329
                 n, p - psuffix, psuffix, n, p - psuffix, psuffix);
2296 2330
 
2297 2331
     switch (flags)
@@ -2522,8 +2556,7 @@ __body
2522 2556
             break;
2523 2557
 
2524 2558
         case 'l':
2525  
-            if (!global.params.useDeprecated)
2526  
-                error("'l' suffix is deprecated, use 'L' instead");
  2559
+            error("'l' suffix is no longer legal, use 'L' instead");
2527 2560
         case 'L':
2528 2561
             result = TOKfloat80v;
2529 2562
             p++;
@@ -2531,8 +2564,8 @@ __body
2531 2564
     }
2532 2565
     if (*p == 'i' || *p == 'I')
2533 2566
     {
2534  
-        if (!global.params.useDeprecated && *p == 'I')
2535  
-            error("'I' suffix is deprecated, use 'i' instead");
  2567
+        if (*p == 'I')
  2568
+            deprecation("'I' suffix is deprecated, use 'i' instead");
2536 2569
         p++;
2537 2570
         switch (result)
2538 2571
         {
2  src/lexer.h
@@ -302,6 +302,8 @@ struct Lexer
302 302
     TOK inreal(Token *t);
303 303
     void error(const char *format, ...);
304 304
     void error(Loc loc, const char *format, ...);
  305
+    void deprecation(const char *format, ...);
  306
+    void deprecation(Loc loc, const char *format, ...);
305 307
     void pragma();
306 308
     unsigned decodeUTF();
307 309
     void getDocComment(Token *t, unsigned lineComment);
31  src/mars.c
@@ -155,6 +155,14 @@ void warning(Loc loc, const char *format, ...)
155 155
     va_end( ap );
156 156
 }
157 157
 
  158
+void deprecation(Loc loc, const char *format, ...)
  159
+{
  160
+    va_list ap;
  161
+    va_start(ap, format);
  162
+    vdeprecation(loc, format, ap);
  163
+    va_end( ap );
  164
+}
  165
+
158 166
 void verror(Loc loc, const char *format, va_list ap)
159 167
 {
160 168
     if (!global.gag)
@@ -208,6 +216,23 @@ void vwarning(Loc loc, const char *format, va_list ap)
208 216
     }
209 217
 }
210 218
 
  219
+void vdeprecation(Loc loc, const char *format, va_list ap)
  220
+{
  221
+    char oldw;
  222
+    switch (global.params.deprecation)
  223
+    {
  224
+    case 2:
  225
+        oldw = global.params.warnings;
  226
+        global.params.warnings = 2; // activate informational warnings temporarly
  227
+        vwarning(loc, format, ap);
  228
+        global.params.warnings = oldw;
  229
+        break;
  230
+    case 1:
  231
+        verror(loc, format, ap);
  232
+        break;
  233
+    }
  234
+}
  235
+
211 236
 /***************************************
212 237
  * Call this after printing out fatal error messages to clean up and exit
213 238
  * the compiler.
@@ -260,6 +285,7 @@ Usage:\n\
260 285
   -Dddocdir      write documentation file to docdir directory\n\
261 286
   -Dffilename    write documentation file to filename\n\
262 287
   -d             allow deprecated features\n\
  288
+  -di            show use of deprecated features as warnings\n\
263 289
   -debug         compile in debug code\n\
264 290
   -debug=level   compile in debug code <= level\n\
265 291
   -debug=ident   compile in debug code identified by ident\n\
@@ -359,6 +385,7 @@ int main(int argc, char *argv[])
359 385
     global.params.obj = 1;
360 386
     global.params.Dversion = 2;
361 387
     global.params.quiet = 1;
  388
+    global.params.deprecation = 1; // deprecated features are errors
362 389
 
363 390
     global.params.linkswitches = new Array();
364 391
     global.params.libfiles = new Array();
@@ -443,7 +470,9 @@ int main(int argc, char *argv[])
443 470
         if (*p == '-')
444 471
         {
445 472
             if (strcmp(p + 1, "d") == 0)
446  
-                global.params.useDeprecated = 1;
  473
+                global.params.deprecation = 0;
  474
+            else if (strcmp(p + 1, "di") == 0)
  475
+                global.params.deprecation = 2;
447 476
             else if (strcmp(p + 1, "c") == 0)
448 477
                 global.params.link = 0;
449 478
             else if (strcmp(p + 1, "cov") == 0)
13  src/mars.h
@@ -146,7 +146,9 @@ struct Param
146 146
     char isOPenBSD;     // generate code for OpenBSD
147 147
     char isSolaris;     // generate code for Solaris
148 148
     char scheduler;     // which scheduler to use
149  
-    char useDeprecated; // allow use of deprecated features
  149
+    char deprecation;   // 0: sillently allow use of deprecated features
  150
+                        // 1: use of deprecated features as errors
  151
+                        // 2: informational warnings (no errors)
150 152
     char useAssert;     // generate runtime code for assert()'s
151 153
     char useInvariants; // generate class invariant checks
152 154
     char useIn;         // generate precondition checks
@@ -247,9 +249,10 @@ struct Global
247 249
     const char *version;
248 250
 
249 251
     Param params;
250  
-    unsigned errors;    // number of errors reported so far
251  
-    unsigned warnings;  // number of warnings reported so far
252  
-    unsigned gag;       // !=0 means gag reporting of errors & warnings
  252
+    unsigned errors;        // number of errors reported so far
  253
+    unsigned warnings;      // number of warnings reported so far
  254
+    unsigned deprecations;  // number of deprecations reported so far
  255
+    unsigned gag;           // !=0 means gag reporting of errors & warnings
253 256
 
254 257
     Global();
255 258
 };
@@ -389,8 +392,10 @@ typedef uint64_t StorageClass;
389 392
 
390 393
 void warning(Loc loc, const char *format, ...);
391 394
 void error(Loc loc, const char *format, ...);
  395
+void deprecation(Loc loc, const char *format, ...);
392 396
 void verror(Loc loc, const char *format, va_list);
393 397
 void vwarning(Loc loc, const char *format, va_list);
  398
+void vdeprecation(Loc loc, const char *format, va_list);
394 399
 void fatal();
395 400
 void err_nomem();
396 401
 int runLINK();
4  src/module.c
@@ -128,8 +128,8 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
128 128
         if (srcfilename->equalsExt("html") ||
129 129
             srcfilename->equalsExt("htm")  ||
130 130
             srcfilename->equalsExt("xhtml"))
131  
-        {   if (!global.params.useDeprecated)
132  
-                error("html source files is deprecated %s", srcfilename->toChars());
  131
+        {
  132
+            deprecation("html source files is deprecated %s", srcfilename->toChars());
133 133
             isHtml = 1;
134 134
         }
135 135
         else
14  src/mtype.c
@@ -56,7 +56,7 @@ FuncDeclaration *hasThis(Scope *sc);
56 56
 #define LOGDEFAULTINIT  0       // log ::defaultInit()
57 57
 
58 58
 // Allow implicit conversion of T[] to T*
59  
-#define IMPLICIT_ARRAY_TO_PTR   global.params.useDeprecated
  59
+#define IMPLICIT_ARRAY_TO_PTR   (global.params.deprecation != 1)
60 60
 
61 61
 /* These have default values for 32 bit code, they get
62 62
  * adjusted for 64 bit code.
@@ -1699,8 +1699,7 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
1699 1699
     }
1700 1700
     else if (ident == Id::typeinfo)
1701 1701
     {
1702  
-        if (!global.params.useDeprecated)
1703  
-            error(loc, ".typeinfo deprecated, use typeid(type)");
  1702
+        deprecation(loc, ".typeinfo deprecated, use typeid(type)");
1704 1703
         e = getTypeInfo(NULL);
1705 1704
     }
1706 1705
     else if (ident == Id::init)
@@ -1768,8 +1767,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
1768 1767
     {
1769 1768
         if (ident == Id::offset)
1770 1769
         {
1771  
-            if (!global.params.useDeprecated)
1772  
-                error(e->loc, ".offset deprecated, use .offsetof");
  1770
+            deprecation(e->loc, ".offset deprecated, use .offsetof");
1773 1771
             goto Loffset;
1774 1772
         }
1775 1773
         else if (ident == Id::offsetof)
@@ -1818,8 +1816,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
1818 1816
     }
1819 1817
     if (ident == Id::typeinfo)
1820 1818
     {
1821  
-        if (!global.params.useDeprecated)
1822  
-            error(e->loc, ".typeinfo deprecated, use typeid(type)");
  1819
+        deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
1823 1820
         e = getTypeInfo(sc);
1824 1821
     }
1825 1822
     else if (ident == Id::stringof)
@@ -7542,8 +7539,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
7542 7539
 
7543 7540
         if (ident == Id::typeinfo)
7544 7541
         {
7545  
-            if (!global.params.useDeprecated)
7546  
-                error(e->loc, ".typeinfo deprecated, use typeid(type)");
  7542
+            deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
7547 7543
             return getTypeInfo(sc);
7548 7544
         }
7549 7545
         if (ident == Id::outer && sym->vthis)
17  src/parse.c
@@ -668,8 +668,7 @@ StorageClass Parser::parsePostfix()
668 668
         {
669 669
             case TOKconst:              stc |= STCconst;                break;
670 670
             case TOKinvariant:
671  
-                if (!global.params.useDeprecated)
672  
-                    error("use of 'invariant' rather than 'immutable' is deprecated");
  671
+                deprecation("use of 'invariant' rather than 'immutable' is deprecated");
673 672
             case TOKimmutable:          stc |= STCimmutable;            break;
674 673
             case TOKshared:             stc |= STCshared;               break;
675 674
             case TOKwild:               stc |= STCwild;                 break;
@@ -2337,8 +2336,7 @@ Type *Parser::parseBasicType()
2337 2336
             break;
2338 2337
 
2339 2338
         case TOKinvariant:
2340  
-            if (!global.params.useDeprecated)
2341  
-                error("use of 'invariant' rather than 'immutable' is deprecated");
  2339
+            deprecation("use of 'invariant' rather than 'immutable' is deprecated");
2342 2340
         case TOKimmutable:
2343 2341
             // invariant(type)
2344 2342
             nextToken();
@@ -2503,10 +2501,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
2503 2501
                  * although the D style would be:
2504 2502
                  *  int[]*[3] ident
2505 2503
                  */
2506  
-                if (!global.params.useDeprecated)
2507  
-                {
2508  
-                    error("C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers");
2509  
-                }
  2504
+                deprecation("C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers");
2510 2505
                 nextToken();
2511 2506
                 ts = parseDeclarator(t, pident);
2512 2507
                 check(TOKrparen);
@@ -3792,8 +3787,7 @@ Statement *Parser::parseStatement(int flags)
3792 3787
                     arg = new Parameter(0, NULL, token.ident, NULL);
3793 3788
                     nextToken();
3794 3789
                     nextToken();
3795  
-                    if (1 || !global.params.useDeprecated)
3796  
-                        error("if (v; e) is deprecated, use if (auto v = e)");
  3790
+                    error("if (v; e) is no longer legal, use if (auto v = e)");
3797 3791
                 }
3798 3792
             }
3799 3793
 
@@ -4159,8 +4153,7 @@ Statement *Parser::parseStatement(int flags)
4159 4153
             nextToken();
4160 4154
             s = parseStatement(PSsemi | PScurlyscope);
4161 4155
 #if DMDV2
4162  
-            if (!global.params.useDeprecated)
4163  
-                error("volatile statements deprecated; used synchronized statements instead");
  4156
+            deprecation("volatile statements deprecated; used synchronized statements instead");
4164 4157
 #endif
4165 4158
             s = new VolatileStatement(loc, s);
4166 4159
             break;
11  src/statement.c
@@ -116,6 +116,14 @@ void Statement::warning(const char *format, ...)
116 116
     va_end( ap );
117 117
 }
118 118
 
  119
+void Statement::deprecation(const char *format, ...)
  120
+{
  121
+    va_list ap;
  122
+    va_start(ap, format);
  123
+    ::vdeprecation(loc, format, ap);
  124
+    va_end( ap );
  125
+}
  126
+
119 127
 int Statement::hasBreak()
120 128
 {
121 129
     //printf("Statement::hasBreak()\n");
@@ -2858,8 +2866,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
2858 2866
     if (!sc->sw->sdefault && !isFinal)
2859 2867
     {   hasNoDefault = 1;
2860 2868
 
2861  
-        if (!global.params.useDeprecated)
2862  
-           error("non-final switch statement without a default is deprecated");
  2869
+        deprecation("non-final switch statement without a default is deprecated");
2863 2870
 
2864 2871
         // Generate runtime error if the default is hit
2865 2872
         Statements *a = new Statements();
1  src/statement.h
@@ -92,6 +92,7 @@ struct Statement : Object
92 92
 
93 93
     void error(const char *format, ...);
94 94
     void warning(const char *format, ...);
  95
+    void deprecation(const char *format, ...);
95 96
     virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
96 97
     int incontract;
97 98
     virtual ScopeStatement *isScopeStatement() { return NULL; }
6  src/toobj.c
@@ -810,13 +810,13 @@ void ClassDeclaration::toObjFile(int multiobj)
810 810
                         continue;
811 811
                     if (fd->leastAsSpecialized(fd2) || fd2->leastAsSpecialized(fd))
812 812
                     {
813  
-                        if (!global.params.useDeprecated)
  813
+                        if (global.params.deprecation)
814 814
                         {
815 815
                             TypeFunction *tf = (TypeFunction *)fd->type;
816 816
                             if (tf->ty == Tfunction)
817  
-                                error("use of %s%s hidden by %s is deprecated\n", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars());
  817
+                                deprecation("use of %s%s hidden by %s is deprecated\n", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars());
818 818
                             else
819  
-                                error("use of %s hidden by %s is deprecated\n", fd->toPrettyChars(), toChars());
  819
+                                deprecation("use of %s hidden by %s is deprecated\n", fd->toPrettyChars(), toChars());
820 820
                         }
821 821
                         s = rtlsym[RTLSYM_DHIDDENFUNC];
822 822
                         break;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.