Ada types with convention CPP_Class are treated as limited types. This change
requires that they are declared with the LIMITED keyword (previously we
already issued a warning in such case). This does not substantially alter
the compiler's treatment of such types, since they were already supposed
to be treated as limited for all practical purposes.

However this does fix some cases where the compiler incorrectly failed to
enforce some of the restrictions associated with limited types. This also
ensures that the use of CPP types does not create violations of the
contract model when a private type has a completion that is a CPP class
(by making it clear on the private view that the type is limited).

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-03  Thomas Quinot  <qui...@adacore.com>

        * sem_prag.adb Issue an error (not a warning) when a C++ type does not
        have keyword LIMITED.

Index: sem_prag.adb
===================================================================
--- sem_prag.adb        (revision 177238)
+++ sem_prag.adb        (working copy)
@@ -4156,24 +4156,18 @@
          elsif Is_Record_Type (Def_Id)
            and then C = Convention_CPP
          then
-            --  Types treated as CPP classes are treated as limited, but we
-            --  don't require them to be declared this way. A warning is issued
-            --  to encourage the user to declare them as limited. This is not
-            --  an error, for compatibility reasons, because these types have
-            --  been supported this way for some time.
+            --  Types treated as CPP classes must be declared limited (note:
+            --  this used to be a warning but there is no real benefit to it
+            --  since we did effectively intend to treat the type as limited
+            --  anyway).
 
             if not Is_Limited_Type (Def_Id) then
                Error_Msg_N
-                 ("imported 'C'P'P type should be " &
-                    "explicitly declared limited?",
+                 ("imported 'C'P'P type must be limited",
                   Get_Pragma_Arg (Arg2));
-               Error_Msg_N
-                 ("\type will be considered limited",
-                  Get_Pragma_Arg (Arg2));
             end if;
 
             Set_Is_CPP_Class (Def_Id);
-            Set_Is_Limited_Record (Def_Id);
 
             --  Imported CPP types must not have discriminants (because C++
             --  classes do not have discriminants).
@@ -7053,24 +7047,18 @@
                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
             end if;
 
-            --  Types treated as CPP classes are treated as limited, but we
-            --  don't require them to be declared this way. A warning is issued
-            --  to encourage the user to declare them as limited. This is not
-            --  an error, for compatibility reasons, because these types have
-            --  been supported this way for some time.
+            --  Types treated as CPP classes must be declared limited (note:
+            --  this used to be a warning but there is no real benefit to it
+            --  since we did effectively intend to treat the type as limited
+            --  anyway).
 
             if not Is_Limited_Type (Typ) then
                Error_Msg_N
-                 ("imported 'C'P'P type should be " &
-                    "explicitly declared limited?",
+                 ("imported 'C'P'P type must be limited",
                   Get_Pragma_Arg (Arg1));
-               Error_Msg_N
-                 ("\type will be considered limited",
-                  Get_Pragma_Arg (Arg1));
             end if;
 
             Set_Is_CPP_Class      (Typ);
-            Set_Is_Limited_Record (Typ);
             Set_Convention        (Typ, Convention_CPP);
 
             --  Imported CPP types must not have discriminants (because C++

Reply via email to