https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65687

            Bug ID: 65687
           Summary: Inconsistent behavior for
                    __attribute__((__deprecated__)) between C and C++.
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iains at gcc dot gnu.org

consider an interface used with a runtime that manipulates data in some
objects:

typedef struct old_visible_stuff *opaquePointer;

struct old_visible_stuff {
  int things_we_no_longer;
  int wish_to_expose;
} __attribute__((__deprecated__("do not refer to this, the layout might
change")));

//A 
opaquePointer runtime_function (opaquePointer someObject);

//B
opaquePointer bad_runtime_call (struct old_visible_stuff *otherObject);

===

The intention here (based on the real-world case of the NeXT ObjC runtime) is
that the layout of the runtime data will become hidden to future versions and
that the User will be expected to interact via accessor methods rather than
directly going to the runtime's data.

At present, this behaves as expected for C (and Objective C) in that case A is
accepted and case B gives a deprecation warning.

However, for C++ both cases A and B produce the warning (which in the real-life
case means a cascade of many many warnings compiling system headers for
Objective-C++).

===

One assumes that, at least the behaviour might be expected to be consistent (or
am I missing some reason why not?)

ISTM looking at cc/cp/dec.c that maybe this was intended:

 static tree
 type_is_deprecated (tree type)
 {
   enum tree_code code;
   if (TREE_DEPRECATED (type))
     return type;
-  if (TYPE_NAME (type)
-      && TREE_DEPRECATED (TYPE_NAME (type)))
-    return type;
+  if (TYPE_NAME (type))
+    return TREE_DEPRECATED (TYPE_NAME (type)) ? type : NULL_TREE;

   /* Do warn about using typedefs to a deprecated class.  */
   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))


rather than falling through, when the TYPE_NAME is not deprecated.

Reply via email to