From 4f260c5e98def6bd1b3498d4085de5080cca7641 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 17 Jul 2026 17:36:59 +0200 Subject: Disallow "[n] const T" --- boot/name_analysis.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'boot') diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index cfc4e35..48251cd 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -51,8 +51,7 @@ namespace elna::boot return "Symbol '" + identifier + "' has been already defined"; } - std::optional> - redefinition_error::note() const + std::optional> redefinition_error::note() const { if (original.has_value() && original->start().available()) { @@ -61,6 +60,16 @@ namespace elna::boot return std::nullopt; } + const_array_error::const_array_error(const source_position position) + : error(position) + { + } + + std::string const_array_error::what() const + { + return "const must be written before the array size, not after"; + } + // Members of a constant aggregate are constant themselves. static type qualify_member_type(const type& element, const type& aggregate) { @@ -176,9 +185,12 @@ namespace elna::boot void name_analysis_visitor::visit(array_type_expression *expression) { walking_visitor::visit(expression); - auto result_type = std::make_shared(this->current_type, expression->size); - this->current_type = type(result_type); + if (this->current_type.get() != nullptr) + { + add_error(expression->position()); + } + this->current_type = type(std::make_shared(this->current_type, expression->size)); } /** -- cgit v1.2.3