The source location of an expression may not be the best place to put a mess in the case of a failed precondition/postcondition/invariant. For example, it gets located on the last "and" keyword in a chain of boolean expressiond and'ed together. It is best put the message on the first character of an assertion, which is done here. This is a follow-up of a previous patch that did the same for pragmas.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-11-23 Yannick Moy <m...@adacore.com> * sem_ch13.adb (Analyze_Aspect_Specifications): Place error on line of precondition/ postcondition/invariant.
Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 181654) +++ sem_ch13.adb (working copy) @@ -728,8 +728,9 @@ A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); Anod : Node_Id; - Eloc : Source_Ptr := Sloc (Expr); - -- Source location of expression, modified when we split PPC's + Eloc : Source_Ptr := No_Location; + -- Source location of expression, modified when we split PPC's. It + -- is set below when Expr is present. procedure Check_False_Aspect_For_Derived_Type; -- This procedure checks for the case of a false aspect for a @@ -804,6 +805,18 @@ goto Continue; end if; + -- Set the source location of expression, used in the case of + -- a failed precondition/postcondition or invariant. Note that + -- the source location of the expression is not usually the best + -- choice here. For example, it gets located on the last AND + -- keyword in a chain of boolean expressiond AND'ed together. + -- It is best to put the message on the first character of the + -- assertion, which is the effect of the First_Node call here. + + if Present (Expr) then + Eloc := Sloc (First_Node (Expr)); + end if; + -- Check restriction No_Implementation_Aspect_Specifications if Impl_Defined_Aspects (A_Id) then