diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 751818d42..155d4ace9 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -135,9 +135,8 @@ These flags affect the general behavior of the compiler. The standards requires that parameters must be declared lexically before they are used. Using -gno-strict-parameter-declaration - will allow using a parameter before declaration, e.g., in a port - declaration, with the parameter declared in the body of the - module. + will allow using a parameter before declaration, with a + warning. The warning can be suppressed with -Wno-anachronisms. * shared-loop-index/no-shared-loop-index diff --git a/compiler.h b/compiler.h index 9548a85d0..eafc8aac9 100644 --- a/compiler.h +++ b/compiler.h @@ -211,8 +211,9 @@ extern bool gn_strict_expr_width_flag; extern bool gn_shared_loop_index_flag; /* If this flag is true (default), then parameters must be declared before - use. - use `-gno-strict-parameter-declaration` for pre version 13 behaviour. + use. `-gno-strict-parameter-declaration` allows to use parameters before + declaration, as prior to version 13. + A warning is emited with -Wanachronisms (default). */ extern bool gn_strict_parameter_declaration; diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 4f7bb40f2..1c0b9e44c 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -153,8 +153,8 @@ numbers are not truncated to integer width. .B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration The standards requires that parameters must be declared lexically before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP -will allow using a parameter before declaration, e.g., in a port -declaration, with the parameter declared in the body of the module. +will allow using a parameter before declaration, with a warning. +The warning can be suppressed with -Wno-anachronisms. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables diff --git a/symbol_search.cc b/symbol_search.cc index 9c00920e7..25f8483e3 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -195,6 +195,12 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->scope = scope; res->par_val = par; res->path_head = path; + if (warn_anachronisms && !prefix_scope + && !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + cerr << li->get_fileline() + << ": warning: parameter `" << path_tail.name + << "` used before declaration." << endl; + } return true; } else if (!res->decl_after_use) { res->decl_after_use = par;