https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016
--- Comment #30 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to qinzhao from comment #29) > (In reply to Jakub Jelinek from comment #28) > > It would need to be a FE keyword where __builtin_get_counted_by would return > > some pointer, either e.g. (void *)0 if it doesn't have a count, or a pointer > > to the count (with type of the pointer dependent on what type the count > > has). > > So, a RID_BUILTIN (i.e, FE keyword) like the following: > > (void *) __builtin_get_counted_by (ptr) Well, without that void *. I think the closest behavior match would be something like __builtin_shuffle (though that has 2 arguments rather than one). Basically, parse the argument expression list, error if it isn't one, determine if it is a FAM with counted_by, if yes, replace the call with &P->COUNT (note, side-effects in the argument need to be evaluated exactly once), otherwise return (void) (P->FAM), (void *) 0 (again, evaluate side-effects but return NULL). > The initial plan is to support it in both C and C++ (since C++ can use > flexible array member too through GCC extension), but I didn't implement it > in C++ in the initial patch. > > If it isn't supported, it should be documented that it doesn't apply to C++ > > and should be rejected in C++. If it is to be supported, the support > > (including support for templates) needs to be there before GCC 15. > I will try to support it in C++ too in GCC15. If not, I will update the > documentation to indicate this limitation. Then perhaps we should ASAP change handle_counted_by_attribute so that it emits a sorry message if (c_dialect_cxx ()), either as the first thing, or perhaps after doing the current diagnostics.