Permalink
Browse files

Merge pull request #556 from 9rnsr/fix3091

Issue 3091 & 6873 - Make "StorageClasses Type" syntax available in some where
  • Loading branch information...
2 parents 36e0a9b + 3f0ccba commit ec3e3300949b5aef30c7a71a0287a77135739144 @don-clugston-sociomantic don-clugston-sociomantic committed Sep 25, 2012
Showing with 82 additions and 12 deletions.
  1. +46 −12 src/parse.c
  2. +1 −0 src/parse.h
  3. +35 −0 test/runnable/xtest46.d
View
@@ -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.
*/
@@ -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
@@ -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)
{
@@ -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;
View
@@ -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);
View
@@ -4638,6 +4638,40 @@ void test2856()
B[1]; // Okay
}
+/***************************************************/
+// 3091
+
+void test3091(inout int = 0)
+{
+ struct Foo {}
+
+ auto pm = new Foo; static assert(is( typeof( pm) == Foo * ));
+ auto pc = new const Foo; static assert(is( typeof( pc) == const(Foo) * ));
+ auto pw = new inout Foo; static assert(is( typeof( pw) == inout(Foo) * ));
+ auto psm = new shared Foo; static assert(is( typeof(psm) == shared(Foo) * ));
+ auto psc = new shared const Foo; static assert(is( typeof(psc) == shared(const(Foo))* ));
+ auto psw = new shared inout Foo; static assert(is( typeof(psw) == shared(inout(Foo))* ));
+ auto pi = new immutable Foo; static assert(is( typeof( pi) == immutable(Foo) * ));
+
+ auto m = Foo(); static assert(is( typeof( m) == Foo ));
+ auto c = const Foo(); static assert(is( typeof( c) == const(Foo) ));
+ auto w = inout Foo(); static assert(is( typeof( w) == inout(Foo) ));
+ auto sm = shared Foo(); static assert(is( typeof(sm) == shared(Foo) ));
+ auto sc = shared const Foo(); static assert(is( typeof(sc) == shared(const(Foo)) ));
+ auto sw = shared inout Foo(); static assert(is( typeof(sw) == shared(inout(Foo)) ));
+ auto i = immutable Foo(); static assert(is( typeof( i) == immutable(Foo) ));
+}
+
+/***************************************************/
+// 6837
+
+template Id6837(T)
+{
+ alias T Id6837;
+}
+static assert(is(Id6837!(shared const int) == shared const int));
+static assert(is(Id6837!(shared inout int) == shared inout int));
+
/***************************************************/
// 6056 fixup
@@ -5544,6 +5578,7 @@ int main()
test6330();
test6868();
test2856();
+ test3091();
test6056();
test7073();
test7150();

0 comments on commit ec3e330

Please sign in to comment.