Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 27, 2012
2 parents 42fd9a9 + 3758556 commit 1299873
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 65 deletions.
19 changes: 16 additions & 3 deletions src/func.c
Expand Up @@ -480,8 +480,8 @@ void FuncDeclaration::semantic(Scope *sc)

doesoverride = TRUE;
#if DMDV2
if (!isOverride())
warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
if (!isOverride() && !global.params.useDeprecated)
::error(loc, "overriding base class function without using override attribute is deprecated (%s overrides %s)", toPrettyChars(), fdv->toPrettyChars());
#endif

FuncDeclaration *fdc = ((Dsymbol *)cd->vtbl.data[vi])->isFuncDeclaration();
Expand Down Expand Up @@ -1236,6 +1236,19 @@ void FuncDeclaration::semantic3(Scope *sc)

if (isCtorDeclaration() && ad)
{
#if DMDV2
// Check for errors related to 'nothrow'.
int nothrowErrors = global.errors;
int blockexit = fbody->blockExit(f->isnothrow);
if (f->isnothrow && (global.errors != nothrowErrors) )
error("'%s' is nothrow yet may throw", toChars());
if (flags & FUNCFLAGnothrowInprocess)
{
flags &= ~FUNCFLAGnothrowInprocess;
if (!(blockexit & BEthrow))
f->isnothrow = TRUE;
}
#endif
//printf("callSuper = x%x\n", sc2->callSuper);

ClassDeclaration *cd = ad->isClassDeclaration();
Expand Down Expand Up @@ -1300,7 +1313,7 @@ void FuncDeclaration::semantic3(Scope *sc)
#if DMDV2
// Check for errors related to 'nothrow'.
int nothrowErrors = global.errors;
int blockexit = fbody ? fbody->blockExit(f->isnothrow) : BEfallthru;
int blockexit = fbody->blockExit(f->isnothrow);
if (f->isnothrow && (global.errors != nothrowErrors) )
error("'%s' is nothrow yet may throw", toChars());
if (flags & FUNCFLAGnothrowInprocess)
Expand Down
58 changes: 46 additions & 12 deletions src/parse.c
Expand Up @@ -724,6 +724,31 @@ StorageClass Parser::parsePostfix()
}
}

StorageClass Parser::parseTypeCtor()
{
StorageClass stc = 0;

while (1)
{
if (peek(&token)->value == TOKlparen)
return stc;
switch (token.value)
{
case TOKconst: stc |= STCconst; break;
case TOKinvariant:
if (!global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
case TOKimmutable: stc |= STCimmutable; break;
case TOKshared: stc |= STCshared; break;
case TOKwild: stc |= STCwild; break;

default: return stc;
}
composeStorageClass(stc);
nextToken();
}
}

/********************************************
* Parse declarations after an align, protection, or extern decl.
*/
Expand Down Expand Up @@ -4448,18 +4473,23 @@ int Parser::isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt)
int haveId = 0;

#if DMDV2
if ((t->value == TOKconst ||
t->value == TOKinvariant ||
t->value == TOKimmutable ||
t->value == TOKwild ||
t->value == TOKshared) &&
peek(t)->value != TOKlparen)
{ /* const type
* immutable type
* shared type
* wild type
*/
t = peek(t);
while (1)
{
if ((t->value == TOKconst ||
t->value == TOKinvariant ||
t->value == TOKimmutable ||
t->value == TOKwild ||
t->value == TOKshared) &&
peek(t)->value != TOKlparen)
{ /* const type
* immutable type
* shared type
* wild type
*/
t = peek(t);
continue;
}
break;
}
#endif

Expand Down Expand Up @@ -5901,7 +5931,9 @@ Expression *Parser::parseUnaryExp()
case TOKinvariant:
case TOKimmutable: // immutable(type)(arguments)
{
StorageClass stc = parseTypeCtor();
Type *t = parseBasicType();
t = t->addSTC(stc);
e = new TypeExp(loc, t);
if (token.value != TOKlparen)
{
Expand Down Expand Up @@ -6511,8 +6543,10 @@ Expression *Parser::parseNewExp(Expression *thisexp)
return e;
}

StorageClass stc = parseTypeCtor();
t = parseBasicType();
t = parseBasicType2(t);
t = t->addSTC(stc);
if (t->ty == Taarray)
{ TypeAArray *taa = (TypeAArray *)t;
Type *index = taa->index;
Expand Down
1 change: 1 addition & 0 deletions src/parse.h
Expand Up @@ -77,6 +77,7 @@ struct Parser : Lexer
void composeStorageClass(StorageClass stc);
StorageClass parseAttribute();
StorageClass parsePostfix();
StorageClass parseTypeCtor();
Expression *parseConstraint();
TemplateDeclaration *parseTemplateDeclaration(int ismixin);
TemplateParameters *parseTemplateParameterList(int flag = 0);
Expand Down
5 changes: 4 additions & 1 deletion test/Makefile
Expand Up @@ -31,12 +31,15 @@
# default: the make variable ARGS (see below)
#
# POST_SCRIPT: name of script to execute after test run
# note: arguments to the script may be included after the name.
# additionally, the name of the file that contains the output
# of the compile/link/run steps is added as the last parameter.
# default: (none)
#
# REQUIRED_ARGS: arguments to add to the $(DMD) command line
# default: (none)
#
# DISABLED: text describing why the test is disabled (if empty, the test is
# DISABLED: text describing why the test is disabled (if empty, the test is
# considered to be enabled).
# default: (none, enabled)

Expand Down
9 changes: 9 additions & 0 deletions test/compilable/deprecate2.d
Expand Up @@ -16,3 +16,12 @@ float distance(point2 a, point2 b)
d[0] = b[0] - a[0]; // if I comment out this line it won't crash
return 0.0f;
}

class A3836
{
void fun() {}
}
class B3836 : A3836
{
void fun() {}
}
8 changes: 4 additions & 4 deletions test/compilable/interpret3.d
Expand Up @@ -3440,11 +3440,11 @@ class SomeClass : TheBase, SomeInterface
int fab;
int a = 17;
int b = 23;
int foo() { return gab + a; }
float bar(char c) { return 2.6; }
override int foo() { return gab + a; }
override float bar(char c) { return 2.6; }
int something() { return 0; }
int daz() { return 0; }
int baz() { return 0; }
override int daz() { return 0; }
override int baz() { return 0; }
}

class Unrelated : TheBase {
Expand Down
36 changes: 21 additions & 15 deletions test/d_do_test.d
Expand Up @@ -252,10 +252,10 @@ string execute(ref File f, string command, bool expectpass)
auto filename = genTempFilename();
scope(exit) removeIfExists(filename);

f.writeln(command);
auto rc = system(command ~ " > " ~ filename ~ " 2>&1");

string output = readText(filename);
f.writeln(command);
f.write(output);

if (WIFSIGNALED(rc))
Expand Down Expand Up @@ -334,12 +334,23 @@ int main(string[] args)

foreach(i, c; combinations(testArgs.permuteArgs))
{
string[] toCleanup;

string test_app_dmd = test_app_dmd_base ~ to!string(i) ~ envData.exe;

try
{
string[] toCleanup;
scope(exit) foreach (file; toCleanup) collectException(std.file.remove(file));

auto thisRunName = genTempFilename();
auto fThisRun = File(thisRunName, "w");
scope(exit)
{
fThisRun.close();
f.write(readText(thisRunName));
f.writeln();
removeIfExists(thisRunName);
}

string compile_output;
if (!testArgs.compileSeparately)
{
Expand All @@ -356,7 +367,7 @@ int main(string[] args)
join(testArgs.sources, " "));
version(Windows) command ~= " -map nul.map";

compile_output = execute(f, command, testArgs.mode != TestMode.FAIL_COMPILE);
compile_output = execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
}
else
{
Expand All @@ -368,7 +379,7 @@ int main(string[] args)

string command = format("%s -m%s -I%s %s %s -od%s -c %s", envData.dmd, envData.model, input_dir,
testArgs.requiredArgs, c, output_dir, filename);
compile_output ~= execute(f, command, testArgs.mode != TestMode.FAIL_COMPILE);
compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
}

if (testArgs.mode == TestMode.RUN)
Expand All @@ -380,7 +391,7 @@ int main(string[] args)
// add after building the command so that before now, it's purely the .o's involved
toCleanup ~= test_app_dmd;

execute(f, command, true);
execute(fThisRun, command, true);
}
}

Expand All @@ -399,22 +410,17 @@ int main(string[] args)
string command = test_app_dmd;
if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs;

execute(f, command, true);
execute(fThisRun, command, true);
}

fThisRun.close();

if (testArgs.postScript)
{
f.write("Executing post-test script: ");
version (Windows) testArgs.postScript = "bash " ~ testArgs.postScript;
execute(f, testArgs.postScript, true);
execute(f, testArgs.postScript ~ " " ~ thisRunName, true);
}

// cleanup
foreach (file; toCleanup)
collectException(std.file.remove(file));

f.writeln();

}
catch(Exception e)
{
Expand Down
13 changes: 13 additions & 0 deletions test/fail_compilation/bug8150a.d
@@ -0,0 +1,13 @@
// Bugzilla 8150: nothrow check doesn't work for constructor

struct Foo
{
this(int) nothrow
{
throw new Exception("something");
}
}

void main() {
Foo(1);
}
13 changes: 13 additions & 0 deletions test/fail_compilation/bug8150b.d
@@ -0,0 +1,13 @@
// Bugzilla 8150: nothrow check doesn't work for constructor

struct Foo
{
this()(int) nothrow
{
throw new Exception("something");
}
}

void main() {
Foo(1);
}
6 changes: 2 additions & 4 deletions test/runnable/bitops.d
Expand Up @@ -9,12 +9,10 @@ void test1()
{
size_t array[2];
uint x;
version (X86)
size_t bitToUse = 35;
else version (X86_64)
version (D_LP64)
size_t bitToUse = 67;
else
static assert(0);
size_t bitToUse = 35;

array[0] = 2;
array[1] = 0x100;
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/extra-files/statictor-postscript.sh
Expand Up @@ -2,7 +2,7 @@

# trim off the first line which contains the path of the file which differs between windows and non-windows
# also trim off compiler debug message
grep -v "runnable\|DEBUG" ${RESULTS_DIR}/runnable/statictor.d.out > ${RESULTS_DIR}/runnable/statictor.d.out.2
grep -v "runnable\|DEBUG" $1 > ${RESULTS_DIR}/runnable/statictor.d.out.2

diff --strip-trailing-cr runnable/extra-files/statictor.d.out ${RESULTS_DIR}/runnable/statictor.d.out.2
if [ $? -ne 0 ]; then
Expand Down
6 changes: 2 additions & 4 deletions test/runnable/test11.d
Expand Up @@ -93,12 +93,10 @@ void test4()
{
byte* p;

version(X86)
assert(p.sizeof == 4);
else version(X86_64)
version(D_LP64)
assert(p.sizeof == 8);
else
assert(false, "unknown platform");
assert(p.sizeof == 4);
}


Expand Down
18 changes: 7 additions & 11 deletions test/runnable/test12.d
Expand Up @@ -683,18 +683,16 @@ class Qwert32
void foo()
{
printf("yuiop = %d, asdfg = %d\n", Qwert32.yuiop.offsetof, Qwert32.asdfg.offsetof);
version(X86)
{
assert(Qwert32.yuiop.offsetof == 8);
assert(Qwert32.asdfg.offsetof == 12);
}
else version (X86_64)
version(D_LP64)
{
assert(Qwert32.yuiop.offsetof == 16);
assert(Qwert32.asdfg.offsetof == 20);
}
else
assert(0);
{
assert(Qwert32.yuiop.offsetof == 8);
assert(Qwert32.asdfg.offsetof == 12);
}
}
}

Expand Down Expand Up @@ -780,12 +778,10 @@ void test36()
printf("%d\n", a.c);
printf("%d\n", a.d);

version(X86)
assert(a.classinfo.init.length == 28);
else version(X86_64)
version(D_LP64)
assert(a.classinfo.init.length == 36);
else
assert(0);
assert(a.classinfo.init.length == 28);
assert(a.s == 1);
assert(a.a == 2);
assert(a.b == 3);
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/testcontracts.d
Expand Up @@ -365,7 +365,7 @@ class P7699
}
class D7699 : P7699
{
void f(int n) in { } body { }
override void f(int n) in { } body { }
}

/*******************************************/
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/traits.d
Expand Up @@ -696,7 +696,7 @@ class EE

class FF : EE
{
final int YYY() { return 4; }
final override int YYY() { return 4; }
}

static assert(__traits(isVirtualMethod, FF.YYY));
Expand Down

0 comments on commit 1299873

Please sign in to comment.