From 3302ced608414973bb197350df448093bfcb75ea Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 18 Dec 2022 16:11:54 -0800 Subject: [PATCH] Report error when trying to declare class methods with static lifetime Class methods with static lifetime are not allowed in SystemVerilog. Report an error when such a method is declared. Note that this is different from static class methods E.g. ``` class C; task static t; endtask // Class method with static lifetime, forbidden static task t; endtask // Static class method, allowed ``` Signed-off-by: Lars-Peter Clausen --- elab_scope.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/elab_scope.cc b/elab_scope.cc index bdab0b879..41723b95d 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -517,7 +517,14 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass) hname_t use_name (cur->first); NetScope*method_scope = new NetScope(class_scope, use_name, NetScope::TASK); + // Task methods are always automatic... + if (!cur->second->is_auto()) { + cerr << "error: Lifetime of method `" + << scope_path(method_scope) + << "` must not be static" << endl; + des->errors += 1; + } method_scope->is_auto(true); method_scope->set_line(cur->second); method_scope->add_imports(&cur->second->explicit_imports); @@ -536,7 +543,14 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass) hname_t use_name (cur->first); NetScope*method_scope = new NetScope(class_scope, use_name, NetScope::FUNC); + // Function methods are always automatic... + if (!cur->second->is_auto()) { + cerr << "error: Lifetime of method `" + << scope_path(method_scope) + << "` must not be static" << endl; + des->errors += 1; + } method_scope->is_auto(true); method_scope->set_line(cur->second); method_scope->add_imports(&cur->second->explicit_imports);