From 895f19174dffc9088c0516f2c8cc47f8f4c589fa Mon Sep 17 00:00:00 2001 From: k-hara Date: Fri, 11 Jan 2013 00:18:59 +0900 Subject: [PATCH] fix Issue 9293 - enum struct with StructInitializer reports weird error `VarDeclaration::getConstInitializer` should return an actual expression, even if init is not an `ExpInitializer`. --- src/declaration.c | 4 ++++ test/runnable/structlit.d | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/declaration.c b/src/declaration.c index 8d1b983cd01e..9413de1664b4 100644 --- a/src/declaration.c +++ b/src/declaration.c @@ -2013,6 +2013,10 @@ Expression *VarDeclaration::getConstInitializer() ExpInitializer *ei = getExpInitializer(); if (ei) return ei->exp; + else if (init) + { + return init->toExpression(); + } } return NULL; diff --git a/test/runnable/structlit.d b/test/runnable/structlit.d index ffce191c6cb5..e54056bcfd27 100644 --- a/test/runnable/structlit.d +++ b/test/runnable/structlit.d @@ -589,6 +589,31 @@ void test9116() assert(y.x.v == 1); // fails } +/********************************************/ +// 9293 + +void test9293() +{ + static struct A + { + // enum A zero = A(); // This works as expected + enum A zero = {}; // Note the difference here + + int opCmp(const ref A a) const + { + assert(0); + } + + int opCmp(const A a) const + { + return 0; + } + } + + A a; + auto b = a >= A.zero; // Error: A() is not an lvalue +} + /********************************************/ int main() @@ -614,6 +639,7 @@ int main() test7929(); test7021(); test9116(); + test9293(); printf("Success\n"); return 0;