tree argval = TREE_VALUE (args);
tree old_counted_by = lookup_attribute ("counted_by", DECL_ATTRIBUTES (decl));
+ /* This attribute is not supported in C++. */
+ if (c_dialect_cxx ())
+ {
+ warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
+ "%qE attribute is not supported for C++ for now, ignored",
+ name);
+ *no_add_attrs = true;
+ }
/* This attribute only applies to field decls of a structure. */
- if (TREE_CODE (decl) != FIELD_DECL)
+ else if (TREE_CODE (decl) != FIELD_DECL)
{
error_at (DECL_SOURCE_LOCATION (decl),
"%qE attribute is not allowed for a non-field"
member of a structure. It indicates that the number of the elements of the
array is given by the field "@var{count}" in the same structure as the
flexible array member.
+
+This attribute is available only in C for now.
+In C++ this attribute is ignored.
+
GCC may use this information to improve detection of object size information
for such structures and provide better results in compile-time diagnostics
and runtime features like the array bound sanitizer and
--- /dev/null
+/* Testing the fact that the attribute counted_by is not supported in C++. */
+/* { dg-do compile { target c++11 } } */
+/* { dg-options "-Wattributes" } */
+
+struct trailing {
+ int count;
+ int field [[gnu::counted_by (count)]] []; /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */
+};
+
+struct trailing1 {
+ int count1;
+ [[gnu::counted_by (count)]] int field []; /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */
+};
--- /dev/null
+/* Testing the fact that the attribute counted_by is not supported in C++. */
+/* { dg-do compile } */
+/* { dg-options "-Wattributes" } */
+
+int size;
+int x __attribute ((counted_by (size))); /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */
+
+struct trailing {
+ int count;
+ int field[] __attribute ((counted_by (count))); /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */
+};