From 5881617a34adc172b830314c17da21d5c834ffd0 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 15 Oct 2012 21:31:02 +0200 Subject: [PATCH] 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. Tests that required -d are updated to use -di options too to ensure -d and -di works exactly the same (except for the compiler messages). Test that didn't really required -d to run (usually obscure bugs only triggered with -d), are now using both -d and -di as PERMUTE_ARGS instead of REQUIRED_ARGS, so the are more generally tested. --- docs/man/man1/dmd.1 | 2 ++ src/dsymbol.c | 2 +- src/mars.c | 10 ++++++++-- src/mars.h | 4 +++- test/compilable/depmsg.d | 1 + test/compilable/deprecate2.d | 1 + test/compilable/header.d | 2 +- test/compilable/test55.d | 2 +- test/compilable/test7754.d | 3 +-- test/fail_compilation/fail108.d | 2 +- test/fail_compilation/fail121.d | 2 +- test/fail_compilation/fail138.d | 2 +- test/fail_compilation/fail156.d | 2 +- test/fail_compilation/fail157.d | 2 +- test/fail_compilation/fail187.d | 2 +- test/fail_compilation/fail4.d | 2 +- test/fail_compilation/testhtml.html | 3 +-- test/fail_compilation/testhtml2.html | 3 +-- test/fail_compilation/testhtml3.html | 3 +-- test/runnable/circular.d | 1 + test/runnable/deprecate1.d | 1 + test/runnable/literal.d | 1 + test/runnable/test9.d | 1 + 23 files changed, 33 insertions(+), 21 deletions(-) diff --git a/docs/man/man1/dmd.1 b/docs/man/man1/dmd.1 index 15166e3fb558..81a34439bd5c 100644 --- a/docs/man/man1/dmd.1 +++ b/docs/man/man1/dmd.1 @@ -33,6 +33,8 @@ Write documentation file to .I filename .IP -d Allow deprecated features. +.IP -di +Show use of deprecated features as warnings. .IP -debug Compile in debug code .IP -debug=\fIlevel\fR diff --git a/src/dsymbol.c b/src/dsymbol.c index 93bae5114204..d2e2871b1b59 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -636,7 +636,7 @@ void Dsymbol::deprecation(const char *format, ...) void Dsymbol::checkDeprecated(Loc loc, Scope *sc) { - if (!global.params.useDeprecated && isDeprecated()) + if (global.params.useDeprecated != 1 && isDeprecated()) { // Don't complain if we're inside a deprecated symbol's scope for (Dsymbol *sp = sc->parent; sp; sp = sp->parent) diff --git a/src/mars.c b/src/mars.c index 4e904ac4a8ad..6b27f9d4340d 100644 --- a/src/mars.c +++ b/src/mars.c @@ -267,8 +267,11 @@ void vwarning(Loc loc, const char *format, va_list ap) void vdeprecation(Loc loc, const char *format, va_list ap, const char *p1, const char *p2) { - if (!global.params.useDeprecated) - verror(loc, format, ap, p1, p2, "Deprecation: "); + static const char *header = "Deprecation: "; + if (global.params.useDeprecated == 0) + verror(loc, format, ap, p1, p2, header); + else if (global.params.useDeprecated == 2 && !global.gag) + verrorPrint(loc, header, format, ap, p1, p2); } /*************************************** @@ -323,6 +326,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\ @@ -527,6 +531,8 @@ int tryMain(int argc, char *argv[]) { if (strcmp(p + 1, "d") == 0) global.params.useDeprecated = 1; + else if (strcmp(p + 1, "di") == 0) + global.params.useDeprecated = 2; else if (strcmp(p + 1, "c") == 0) global.params.link = 0; else if (strcmp(p + 1, "cov") == 0) diff --git a/src/mars.h b/src/mars.h index 42568a4a7481..b3229b3dc94b 100644 --- a/src/mars.h +++ b/src/mars.h @@ -158,7 +158,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 useDeprecated; // 0: don't allow use of deprecated features + // 1: silently allow use of deprecated features + // 2: warn about the use of deprecated features char useAssert; // generate runtime code for assert()'s char useInvariants; // generate class invariant checks char useIn; // generate precondition checks diff --git a/test/compilable/depmsg.d b/test/compilable/depmsg.d index 08817e5fd697..ef9e4dfaaf29 100644 --- a/test/compilable/depmsg.d +++ b/test/compilable/depmsg.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di void main() { diff --git a/test/compilable/deprecate2.d b/test/compilable/deprecate2.d index e73168d93ab5..3d8cc3f66598 100644 --- a/test/compilable/deprecate2.d +++ b/test/compilable/deprecate2.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di // Test cases using deprecated features diff --git a/test/compilable/header.d b/test/compilable/header.d index fc0e60133c61..970631b21d77 100644 --- a/test/compilable/header.d +++ b/test/compilable/header.d @@ -1,4 +1,4 @@ -// PERMUTE_ARGS: +// PERMUTE_ARGS: -di // REQUIRED_ARGS: -H -Hdtest_results/compilable // POST_SCRIPT: compilable/extra-files/header-postscript.sh // REQUIRED_ARGS: -d diff --git a/test/compilable/test55.d b/test/compilable/test55.d index 6e3dbc4ced2e..e79fb38abf8f 100644 --- a/test/compilable/test55.d +++ b/test/compilable/test55.d @@ -1,6 +1,6 @@ // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test55a.d -// PERMUTE_ARGS: +// PERMUTE_ARGS: -di // REQUIRED_ARGS: -d public import imports.test55a; diff --git a/test/compilable/test7754.d b/test/compilable/test7754.d index 9ba6d462e894..310a4259c8f7 100644 --- a/test/compilable/test7754.d +++ b/test/compilable/test7754.d @@ -1,7 +1,6 @@ -// PERMUTE_ARGS: // REQUIRED_ARGS: -H -Hdtest_results/compilable // POST_SCRIPT: compilable/extra-files/test7754-postscript.sh -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di struct Foo(T) { diff --git a/test/fail_compilation/fail108.d b/test/fail_compilation/fail108.d index 2ec00702b7c5..be8909ef08ed 100644 --- a/test/fail_compilation/fail108.d +++ b/test/fail_compilation/fail108.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di // 249 module test1; diff --git a/test/fail_compilation/fail121.d b/test/fail_compilation/fail121.d index 9be14a7c7130..894fa7db9155 100644 --- a/test/fail_compilation/fail121.d +++ b/test/fail_compilation/fail121.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di // segfault on DMD0.150, never failed if use typeid() instead. struct myobject diff --git a/test/fail_compilation/fail138.d b/test/fail_compilation/fail138.d index 6e90dceeddf1..0dc73deb9fa2 100644 --- a/test/fail_compilation/fail138.d +++ b/test/fail_compilation/fail138.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di typedef int T = void; diff --git a/test/fail_compilation/fail156.d b/test/fail_compilation/fail156.d index 062f9f063e1e..fa304e9a7b9d 100644 --- a/test/fail_compilation/fail156.d +++ b/test/fail_compilation/fail156.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di typedef int myint = 4; diff --git a/test/fail_compilation/fail157.d b/test/fail_compilation/fail157.d index 3ba962552230..14b02e505f3a 100644 --- a/test/fail_compilation/fail157.d +++ b/test/fail_compilation/fail157.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di typedef int myint = 4; diff --git a/test/fail_compilation/fail187.d b/test/fail_compilation/fail187.d index 35b6b003a7fa..e5e697937f3b 100644 --- a/test/fail_compilation/fail187.d +++ b/test/fail_compilation/fail187.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di // On DMD 2.000 bug only with typedef, not alias typedef Exception A; diff --git a/test/fail_compilation/fail4.d b/test/fail_compilation/fail4.d index f5135fb60c2d..2d2b0ca87c43 100644 --- a/test/fail_compilation/fail4.d +++ b/test/fail_compilation/fail4.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -d -di // On DMD0.165 fails only with typedef, not alias typedef foo bar; diff --git a/test/fail_compilation/testhtml.html b/test/fail_compilation/testhtml.html index e5649a08308a..271a564fa687 100644 --- a/test/fail_compilation/testhtml.html +++ b/test/fail_compilation/testhtml.html @@ -1,7 +1,6 @@ dstress: html_entity_01

 int main(){
diff --git a/test/fail_compilation/testhtml2.html b/test/fail_compilation/testhtml2.html
index 12ee56b44259..525f7ff0ead1 100644
--- a/test/fail_compilation/testhtml2.html
+++ b/test/fail_compilation/testhtml2.html
@@ -1,4 +1,3 @@
 
	dstress: html_line_ending_mac
	

// __DSTRESS_TORTURE_BLOCK__ -release
 int main(){
	try{
		assert(0);
	}catch(Throwable e){
		checkLineNumber(e);
		return 0;
	}
	assert(-1, "b");
	return 1;
}

/*
 * @WARNING@ this code depends on the phobos implementation.
 * char[]s returned by wrong assertions have to look like:
 *	 "blah blah (linenumber) blah blah"
 */
void checkLineNumber(Object o){
	string x=o.toString();

	int start;
	for(start=0; start<x.length; start++){if(x[start]=='('){break;}}

	int end;
	for(end=start+1; end<x.length; end++){if(x[end]==')'){break;}}

	assert(end-start==3);
	assert(x[start+1 .. end]=="10", x[start+1 .. end]);
}
	
diff --git a/test/fail_compilation/testhtml3.html b/test/fail_compilation/testhtml3.html index 8f0efd57dad7..95d8f13e0771 100644 --- a/test/fail_compilation/testhtml3.html +++ b/test/fail_compilation/testhtml3.html @@ -1,7 +1,6 @@ dstress: html_tag_space_01 diff --git a/test/runnable/circular.d b/test/runnable/circular.d index 843715d7685d..fcbe6ccd60ae 100644 --- a/test/runnable/circular.d +++ b/test/runnable/circular.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di // EXTRA_SOURCES: imports/circularA.d // This bug is typedef-specific. diff --git a/test/runnable/deprecate1.d b/test/runnable/deprecate1.d index efc0c571b46f..aba244e364e6 100644 --- a/test/runnable/deprecate1.d +++ b/test/runnable/deprecate1.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di // Test cases using deprecated features module deprecate1; diff --git a/test/runnable/literal.d b/test/runnable/literal.d index f581b203d428..40e785025f34 100644 --- a/test/runnable/literal.d +++ b/test/runnable/literal.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di import std.stdio; import std.c.stdlib; diff --git a/test/runnable/test9.d b/test/runnable/test9.d index 316c28c73414..08d00d2758c5 100644 --- a/test/runnable/test9.d +++ b/test/runnable/test9.d @@ -1,4 +1,5 @@ // REQUIRED_ARGS: -d +// PERMUTE_ARGS: -di // The use of typedef in these tests is fundamental. public: