Skip to content

Commit

Permalink
Merge pull request dlang#63 from 9rnsr/fix5962
Browse files Browse the repository at this point in the history
Issue 5962 - Template function declaration with prefixed storage class and auto occurs conflict
  • Loading branch information
WalterBright committed Jul 1, 2011
2 parents 5a1f396 + 031bdab commit 781df82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,7 @@ Type *Parser::parseBasicType2(Type *t)
return NULL;
}

Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl)
Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl, StorageClass storage_class)
{ Type *ts;

//printf("parseDeclarator(tpl = %p)\n", tpl);
Expand Down Expand Up @@ -2604,6 +2604,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
/* Parse const/immutable/shared/inout/nothrow/pure postfix
*/
StorageClass stc = parsePostfix();
stc |= storage_class; // merge prefix storage classes
Type *tf = new TypeFunction(arguments, t, varargs, linkage, stc);

if (stc & STCconst)
Expand Down Expand Up @@ -2818,7 +2819,7 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
TemplateParameters *tpl = NULL;

ident = NULL;
t = parseDeclarator(ts, &ident, &tpl);
t = parseDeclarator(ts, &ident, &tpl, storage_class);
assert(t);
if (!tfirst)
tfirst = t;
Expand Down Expand Up @@ -2881,6 +2882,9 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
tpl = new TemplateParameters();
}
#endif

//printf("%s funcdecl t = %s, storage_class = x%lx\n", loc.toChars(), t->toChars(), storage_class);

FuncDeclaration *f =
new FuncDeclaration(loc, 0, ident, storage_class, t);
addComment(f, comment);
Expand Down
2 changes: 1 addition & 1 deletion src/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct Parser : Lexer
Type *parseType(Identifier **pident = NULL, TemplateParameters **tpl = NULL);
Type *parseBasicType();
Type *parseBasicType2(Type *t);
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL);
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL, StorageClass storage_class = 0);
Dsymbols *parseDeclarations(StorageClass storage_class, unsigned char *comment);
void parseContracts(FuncDeclaration *f);
Statement *parseStatement(int flags);
Expand Down
14 changes: 14 additions & 0 deletions test/runnable/bug5962.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 5962

struct S
{
auto g()(){ return 1; }
const auto g()(){ return 2; }
}
void main()
{
auto ms = S();
assert(ms.g() == 1);
auto cs = const(S)();
assert(cs.g() == 2);
}

0 comments on commit 781df82

Please sign in to comment.