comp.lang.ada
 help / color / mirror / Atom feed
* suppress "unspecified order" error in gnat?
@ 2019-03-15 23:50 Stephen Leake
  2019-03-18 23:25 ` Randy Brukardt
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Leake @ 2019-03-15 23:50 UTC (permalink / 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-18 23:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-15 23:50 suppress "unspecified order" error in gnat? Stephen Leake
2019-03-18 23:25 ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox