diff options
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index c03d8e985..1331839a4 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2512,6 +2512,23 @@ static Expr* constructDefaultConstructorForType(SemanticsVisitor* visitor, Type* return invoke; } + // At the last, we will check if the type is a C-style type, if it is, we will use empty + // initializer list to construct the default constructor. + HashSet<Type*> visitSet; + if (visitor->isCStyleType(type, visitSet)) + { + auto initListExpr = visitor->getASTBuilder()->create<InitializerListExpr>(); + initListExpr->type = visitor->getASTBuilder()->getInitializerListType(); + Expr* outExpr = nullptr; + auto fromType = type; + if (auto atomicType = as<AtomicType>(fromType)) + { + fromType = atomicType->getElementType(); + } + if (visitor->_coerceInitializerList(fromType, &outExpr, initListExpr)) + return outExpr; + } + return nullptr; } @@ -13031,7 +13048,13 @@ static Expr* _getParamDefaultValue(SemanticsVisitor* visitor, VarDeclBase* varDe if (!isDefaultInitializable(varDecl)) return nullptr; - return constructDefaultConstructorForType(visitor, varDecl->type.type); + if (auto expr = constructDefaultConstructorForType(visitor, varDecl->type.type)) + { + expr->loc = varDecl->loc; + return expr; + } + + return nullptr; } bool SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* structDecl) |
