Fran�oise & Herv� BITTEUR writes: > I just run in a problem when combining : > - Ada.Strings.Bounded where '=' operator is redefined, > - A so far correct generic package (old Ada83 code) importing a private > (non-limited) type. > > The problem is that any instantiation of the generic package will use > the "predefined" equality operator provided with any non-limited type, > rather than the specific definition related to Ada.Strings.Bounded. > Which leads to unexpected results on some occasions. This phenonmenon is called "reemergence of predefined operators," and it's one of Ada's trap doors. When you import a (non-tagged) type as a formal type, without also explicitly importing operators, then the predefined operators for the type are used, irrespective of whether the actual type has redefined them. > I have attached a very simplified example to illustrate the situation. > An obvious fix is to modify the spec of the generic package to > explicitly import a definition of '=' : > with function "=" (L, R : in Item) return Boolean is <>; > And the redefined version if any (or the predefined one if none) will > then be used. ALWAYS import equality for any non-tagged formal type. In the data structure library I'm building, every private type is imported as generic type Item_Type is private; with function "=" (L, R : Item_Type) return Boolean is <>; ... package ACL.Stacks.Adapters is ... > But what puzzles me is that : > 1/ No warning is raised by the compiler (how could it be otherwise ?) Unfortunately, this is a "feature" of the language, not a flaw. > Would you thus recommend that the line above ("with function "=" ...) be > systematically added to each and every existing generic package using > non-limited parameters ? Yes. Always.