diff --git a/src/parse.c b/src/parse.c index 1622d919f4d3..fd7a2f62be57 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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); @@ -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) @@ -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; @@ -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); diff --git a/src/parse.h b/src/parse.h index 855e3c01b90b..9319503a3e86 100644 --- a/src/parse.h +++ b/src/parse.h @@ -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); diff --git a/test/runnable/bug5962.d b/test/runnable/bug5962.d new file mode 100644 index 000000000000..205cc5ae117f --- /dev/null +++ b/test/runnable/bug5962.d @@ -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); +}