Hi,
On 10/24/2012 06:57 PM, Jason Merrill wrote:
On 10/10/2012 11:13 AM, Paolo Carlini wrote:
- error ("type transparent class %qT does not have any fields", t);
+ if (TREE_CODE (t) == UNION_TYPE)
+ error ("type transparent union %qT does not have any
fields", t);
+ else
+ error ("type transparent class %qT does not have any
fields", t);
If you use %q#T you don't need to repeat the class-key.
Indeed.
+ error ("type transparent union %qT cannot be made
transparent", t);
Let's say why not.
Thus I tested the below.
Thanks,
Paolo.
//////////////////////
Index: cp/class.c
===================================================================
--- cp/class.c (revision 192762)
+++ cp/class.c (working copy)
@@ -6261,7 +6261,7 @@ finish_struct_1 (tree t)
tree field = first_field (t);
if (field == NULL_TREE || error_operand_p (field))
{
- error ("type transparent class %qT does not have any fields", t);
+ error ("type transparent %q#T does not have any fields", t);
TYPE_TRANSPARENT_AGGR (t) = 0;
}
else if (DECL_ARTIFICIAL (field))
@@ -6275,6 +6275,12 @@ finish_struct_1 (tree t)
}
TYPE_TRANSPARENT_AGGR (t) = 0;
}
+ else if (TYPE_MODE (t) != DECL_MODE (field))
+ {
+ error ("type transparent %q#T cannot be made transparent because "
+ "a field has neither pointer nor integer type", t);
+ TYPE_TRANSPARENT_AGGR (t) = 0;
+ }
}
}
Index: testsuite/g++.dg/ext/transparent-union.C
===================================================================
--- testsuite/g++.dg/ext/transparent-union.C (revision 0)
+++ testsuite/g++.dg/ext/transparent-union.C (working copy)
@@ -0,0 +1,5 @@
+// PR c++/53761
+
+typedef union { // { dg-error "type transparent" }
+ double x;
+} __attribute__(( __transparent_union__ )) example_t;