Skip to content

Commit

Permalink
Merge pull request #4458 from mihails-strasuns-sociomantic/redundant-…
Browse files Browse the repository at this point in the history
…attrib-deprec

[REG] fix Issue 14232 : redundant attribute 'const'
  • Loading branch information
MartinNowak committed Mar 10, 2015
2 parents 25b0115 + 8bfa318 commit 53c5b59
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
12 changes: 9 additions & 3 deletions src/parse.c
Expand Up @@ -930,9 +930,12 @@ Dsymbols *Parser::parseDeclDefs(int once, Dsymbol **pLastDecl, PrefixAttributes

/*********************************************
* Give error on redundant/conflicting storage class.
*
* TODO: remove deprecation in 2.068 and keep only error
*/

StorageClass Parser::appendStorageClass(StorageClass storageClass, StorageClass stc)
StorageClass Parser::appendStorageClass(StorageClass storageClass, StorageClass stc,
bool deprec)
{
if ((storageClass & stc) ||
(storageClass & STCin && stc & (STCconst | STCscope)) ||
Expand All @@ -942,7 +945,10 @@ StorageClass Parser::appendStorageClass(StorageClass storageClass, StorageClass
StorageClassDeclaration::stcToCBuffer(&buf, stc);
if (buf.data[buf.offset - 1] == ' ')
buf.data[buf.offset - 1] = '\0';
error("redundant attribute '%s'", buf.peekString());
if (deprec)
deprecation("redundant attribute '%s'", buf.peekString());
else
error("redundant attribute '%s'", buf.peekString());
return storageClass | stc;
}

Expand Down Expand Up @@ -1080,7 +1086,7 @@ StorageClass Parser::parsePostfix(StorageClass storageClass, Expressions **pudas
default:
return storageClass;
}
storageClass = appendStorageClass(storageClass, stc);
storageClass = appendStorageClass(storageClass, stc, true);
nextToken();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse.h
Expand Up @@ -79,7 +79,7 @@ class Parser : public Lexer
Dsymbols *parseDeclDefs(int once, Dsymbol **pLastDecl = NULL, PrefixAttributes *pAttrs = NULL);
Dsymbols *parseAutoDeclarations(StorageClass storageClass, const utf8_t *comment);
Dsymbols *parseBlock(Dsymbol **pLastDecl, PrefixAttributes *pAttrs = NULL);
StorageClass appendStorageClass(StorageClass storageClass, StorageClass stc);
StorageClass appendStorageClass(StorageClass storageClass, StorageClass stc, bool deprec = false);
StorageClass parseAttribute(Expressions **pexps);
StorageClass parsePostfix(StorageClass storageClass, Expressions **pudas);
StorageClass parseTypeCtor();
Expand Down
20 changes: 10 additions & 10 deletions test/fail_compilation/parseStc3.d
@@ -1,10 +1,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/parseStc3.d(10): Error: redundant attribute 'pure'
fail_compilation/parseStc3.d(11): Error: redundant attribute 'nothrow'
fail_compilation/parseStc3.d(12): Error: redundant attribute '@nogc'
fail_compilation/parseStc3.d(13): Error: redundant attribute '@property'
fail_compilation/parseStc3.d(10): Deprecation: redundant attribute 'pure'
fail_compilation/parseStc3.d(11): Deprecation: redundant attribute 'nothrow'
fail_compilation/parseStc3.d(12): Deprecation: redundant attribute '@nogc'
fail_compilation/parseStc3.d(13): Deprecation: redundant attribute '@property'
---
*/
pure void f1() pure {}
Expand All @@ -16,9 +16,9 @@ nothrow void f2() nothrow {}
/*
TEST_OUTPUT:
---
fail_compilation/parseStc3.d(24): Error: redundant attribute '@safe'
fail_compilation/parseStc3.d(25): Error: redundant attribute '@system'
fail_compilation/parseStc3.d(26): Error: redundant attribute '@trusted'
fail_compilation/parseStc3.d(24): Deprecation: redundant attribute '@safe'
fail_compilation/parseStc3.d(25): Deprecation: redundant attribute '@system'
fail_compilation/parseStc3.d(26): Deprecation: redundant attribute '@trusted'
---
*/
@safe void f6() @safe {}
Expand Down Expand Up @@ -49,11 +49,11 @@ TEST_OUTPUT:
fail_compilation/parseStc3.d(59): Error: conflicting attribute '@system'
fail_compilation/parseStc3.d(59): Error: conflicting attribute '@trusted'
fail_compilation/parseStc3.d(60): Error: conflicting attribute '@system'
fail_compilation/parseStc3.d(60): Error: redundant attribute '@system'
fail_compilation/parseStc3.d(60): Deprecation: redundant attribute '@system'
fail_compilation/parseStc3.d(61): Error: conflicting attribute '@safe'
fail_compilation/parseStc3.d(61): Error: redundant attribute '@system'
fail_compilation/parseStc3.d(61): Deprecation: redundant attribute '@system'
fail_compilation/parseStc3.d(62): Error: conflicting attribute '@safe'
fail_compilation/parseStc3.d(62): Error: redundant attribute '@trusted'
fail_compilation/parseStc3.d(62): Deprecation: redundant attribute '@trusted'
---
*/
@safe @system void f15() @trusted {}
Expand Down
20 changes: 10 additions & 10 deletions test/fail_compilation/parseStc4.d
Expand Up @@ -2,11 +2,11 @@
/*
TEST_OUTPUT:
---
fail_compilation/parseStc4.d(14): Error: redundant attribute 'pure'
fail_compilation/parseStc4.d(14): Error: redundant attribute 'nothrow'
fail_compilation/parseStc4.d(14): Deprecation: redundant attribute 'pure'
fail_compilation/parseStc4.d(14): Deprecation: redundant attribute 'nothrow'
fail_compilation/parseStc4.d(14): Error: conflicting attribute '@system'
fail_compilation/parseStc4.d(14): Error: redundant attribute '@nogc'
fail_compilation/parseStc4.d(14): Error: redundant attribute '@property'
fail_compilation/parseStc4.d(14): Deprecation: redundant attribute '@nogc'
fail_compilation/parseStc4.d(14): Deprecation: redundant attribute '@property'
---
*/
pure nothrow @safe @nogc @property
Expand All @@ -19,12 +19,12 @@ pure nothrow @system @nogc @property
/*
TEST_OUTPUT:
---
fail_compilation/parseStc4.d(34): Error: redundant attribute 'const'
fail_compilation/parseStc4.d(35): Error: redundant attribute 'const'
fail_compilation/parseStc4.d(36): Error: redundant attribute 'const'
fail_compilation/parseStc4.d(38): Error: redundant attribute 'pure'
fail_compilation/parseStc4.d(39): Error: redundant attribute '@safe'
fail_compilation/parseStc4.d(40): Error: redundant attribute 'nothrow'
fail_compilation/parseStc4.d(34): Deprecation: redundant attribute 'const'
fail_compilation/parseStc4.d(35): Deprecation: redundant attribute 'const'
fail_compilation/parseStc4.d(36): Deprecation: redundant attribute 'const'
fail_compilation/parseStc4.d(38): Deprecation: redundant attribute 'pure'
fail_compilation/parseStc4.d(39): Deprecation: redundant attribute '@safe'
fail_compilation/parseStc4.d(40): Deprecation: redundant attribute 'nothrow'
fail_compilation/parseStc4.d(41): Error: conflicting attribute '@trusted'
---
*/
Expand Down

0 comments on commit 53c5b59

Please sign in to comment.