From 47d9ebdbf05abe6a01414094375394e994015cee Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Sun, 2 Apr 2023 11:14:45 -0700 Subject: [PATCH] Require namespace-scope objects to have a concrete type, closes #315 --- source/parse.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/parse.h b/source/parse.h index 3e87420643..78de7afbbf 100644 --- a/source/parse.h +++ b/source/parse.h @@ -1934,7 +1934,7 @@ struct declaration_node ; } - auto is_wildcard() const + auto has_wildcard_type() const -> bool { return @@ -5488,6 +5488,14 @@ class parser // First see if it's an alias declaration n = alias(); if (n) { + if (is_parameter) { + errors.emplace_back( + curr().position(), + "a parameter declaration may not be an alias declaration" + ); + return {}; + } + n->pos = start_pos; n->identifier = std::move(id); n->access = access; @@ -5513,6 +5521,20 @@ class parser // Note: Do this after trying to parse this as a declaration, for parse backtracking + if ( + !is_parameter + && n->is_object() + && n->has_wildcard_type() + && n->parent_is_namespace() + ) + { + errors.emplace_back( + n->identifier->position(), + "namespace scope objects must have a concrete type, not a deduced type" + ); + return {}; + } + if ( n->has_name("_") && !n->is_object()