Skip to content

Commit eff16f9

Browse files
committed
Fix #4938 - Be stricter wrt. supported AddrExp in toConstElem()
DMD seems to support AddrExp of struct literals only...
1 parent fec7371 commit eff16f9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

gen/toconstelem.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class ToConstElemVisitor : public Visitor {
401401
return;
402402
}
403403

404-
// address of indexExp
404+
/* address of indexExp
405405
if (auto iexp = e->e1->isIndexExp()) {
406406
// indexee must be global static array var
407407
VarExp *vexp = iexp->e1->isVarExp();
@@ -426,6 +426,7 @@ class ToConstElemVisitor : public Visitor {
426426
result = gep;
427427
return;
428428
}
429+
*/
429430

430431
if (auto se = e->e1->isStructLiteralExp()) {
431432
result = p->getStructLiteralGlobal(se);
@@ -449,12 +450,7 @@ class ToConstElemVisitor : public Visitor {
449450
return;
450451
}
451452

452-
if (e->e1->op == EXP::slice || e->e1->op == EXP::dotVariable) {
453-
visit(static_cast<Expression *>(e));
454-
return;
455-
}
456-
457-
llvm_unreachable("unsupported AddrExp in ToConstElemVisitor");
453+
visit(static_cast<Expression *>(e));
458454
}
459455

460456
//////////////////////////////////////////////////////////////////////////////

tests/fail_compilation/gh4938.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not %ldc -c %s 2>&1 | FileCheck %s
2+
3+
// CHECK: gh4938.d(4): Error: expression `&"whoops"w[0]` is not a constant
4+
immutable(wchar)* x = &"whoops"w[0];

0 commit comments

Comments
 (0)