]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious warning about negative modular literal
authorSteve Baird <baird@adacore.com>
Thu, 10 Aug 2023 22:39:01 +0000 (15:39 -0700)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 5 Sep 2023 11:05:13 +0000 (13:05 +0200)
If -gnatw.m is enabled, the compiler generates a warning if a unary
minus operator of a modular type is applied to an integer literal.
This warning was being incorrectly generated in some cases where no integer
literal is present in the source code.

gcc/ada/

* sem_res.adb (Resolve_Unary_Op): In deciding whether to emit a
warning about a modular type's unary minus operator being applied
to an integer literal, ignore integer literals for which
Comes_From_Source is False.

gcc/ada/sem_res.adb

index 9755e4d14a6d4f82c8a0c5818a66d2a354a90b3c..c708d04fc32a73a46ed0b05a497ea5843d239efb 100644 (file)
@@ -12671,6 +12671,7 @@ package body Sem_Res is
       if Warn_On_Suspicious_Modulus_Value
         and then Nkind (N) = N_Op_Minus
         and then Nkind (R) = N_Integer_Literal
+        and then Comes_From_Source (R)
         and then Is_Modular_Integer_Type (B_Typ)
         and then Nkind (Parent (N)) not in N_Qualified_Expression
                                          | N_Type_Conversion