From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: suppress "unspecified order" error in gnat?
Date: Fri, 15 Mar 2019 16:50:37 -0700 (PDT)
Date: 2019-03-15T16:50:37-07:00 [thread overview]
Message-ID: <f09c8b98-5f65-4a63-bbc7-b192ad906113@googlegroups.com> (raw)
I'd like to compile the following:
New_Nonterm : constant Valid_Node_Index := Tree.Add_Nonterm
((+nonterminal_ID, 0),
(1 => Tree.Add_Identifier (+IDENTIFIER_ID, New_Identifier),
2 => Tree.Add_Terminal (+COLON_ID),
3 => RHS_Alt_Node,
4 => Tree.Add_Nonterm
((+semicolon_opt_ID, 0),
(1 => Tree.Add_Terminal (+SEMICOLON_ID)))));
but GNAT complains:
wisitoken_grammar_runtime.adb:715:19: value of actual may be affected by call in other actual because they are evaluated in unspecified order
Here "Tree" is a syntax tree, and the various Tree.Add_* functions insert items in the tree and return a tree node id.
In this case, it does not matter what order the aggregate elements are evaluated in. Normally I applaud this error, but I'd like to turn it off in this case.
Applying 'pragma Warnings' doesn't work, because this is not a warning; it's an error.
Surprisingly, I can write a subprogram to work around this; the above becomes
New_Nonterm : constant Valid_Node_Index := Add_Nonterm
((+nonterminal_ID, 0),
Child_1 => Tree.Add_Identifier (+IDENTIFIER_ID, New_Identifier),
Child_2 => Tree.Add_Terminal (+COLON_ID),
Child_3 => RHS_Alt_Node,
Child_4 => Tree.Add_Nonterm
((+semicolon_opt_ID, 0),
(1 => Tree.Add_Terminal (+SEMICOLON_ID))));
Note that Child_1 .. Child_4 are also evaluated in an arbitrary order, according to the ARM (6.4 10). Maybe GNAT imposes an order here, but not in an aggregate?
But I have similar statements that are harder to work around:
Tree.Set_Children
(Comp_Unit_List_Tail,
(1 => Tree.Add_Nonterm
((+compilation_unit_list_ID, 0),
(1 => Tree.Add_Nonterm
((+compilation_unit_ID, 1),
(1 => New_Nonterm))))));
Here I need to declare some local vars to enforce an order. Ugly. This aggregate nicely reflects the actual tree structure; morphing it to use local vars destroys that.
next reply other threads:[~2019-03-15 23:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 23:50 Stephen Leake [this message]
2019-03-18 23:25 ` suppress "unspecified order" error in gnat? Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox