Emit a warning with -gno-strict-parameter-declaration
When a parameter is used before declaration, a warning is printed, unless `-Wno-anachronisms`.
This commit is contained in:
parent
ab74cafa20
commit
1f8991e382
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue