(TL;DR: I came at this with the impression that aspects, just like pragmas, could be ignored when unknown. This seems not to be mandated, but only allowed, by the ARM 2022.)
The idea I was attempting is that a library can use Ada 2022 features but an Ada 2012 client can still “with” it, without maintaining two sets of sources, by ignoring unknown pragmas.
However, “future” aspects are reported as an error (using GNAT 14.1):
pragma Ada_2012;
package Multiver is
type Modern is null record
with Aggregate => (Empty => Empty,
Add_Unnamed => Drop),
Integer_Literal => From_Int,
Unknown_Aspect;
function Empty return Modern is (null record);
procedure Drop (X : in out Modern; I : Integer) is null;
function From_Int (X : String) return Modern is (Empty);
end Multiver;
Output:
multiver.ads:6:24: error: incompatible with Ada version set at line 1
multiver.ads:9:11: warning: "Unknown_Aspect" is not a valid aspect identifier [enabled by default]
That’s a self-contained example, but the same happens in the intended usage with two separate projects, library using -gnat2022
and client withing Multiver
using -gnat12
and no Pragma Ada_2012
in the source.
Note:
- Expected warning on line 9
- Error instead of warning on line 6
- Unexpected silence about line 8, which is maybe a bug.
So the thing is: if that error could be downgraded to a warning, I could have my cake and eat it.
(Just tested that the same happens with all GNATs in Alire, from 11 upwards. GNAT 10 rejects all unknown aspects).
After some digging, I find that the ARM 2012 says nothing about unknown aspects. The ARM 2022 gives permission to ignore unknown aspects: 13.1 Operational and Representation Aspects | Ada Programming Language, but does not mandate it so…
This seems to come from Version 1.4 of ai12s/ai12-0389-1.txt
So, after all that, I think it boils down to: is there some GNAT switch to enable ignoring all unknown aspects? Not practical for me anymore, since older GNATs would likely not have it, but at this point I’m just curious. And the lesson learned is that aspects are not just syntactic sugar on top of pragmas.