On 11/3/26 6:18 PM, Joseph Myers wrote:
On Tue, 3 Nov 2026, Jason Merrill wrote:
@@ -2098,6 +2100,14 @@ type_promotes_to (tree type)
else if (type == float_type_node)
type = double_type_node;
+ if (no_implicit_truncation)
+ {
+ tree attrs = tree_cons (get_identifier ("no_implicit_truncation"),
+ NULL_TREE,
+ TYPE_ATTRIBUTES (type));
+ type = cp_build_type_attribute_variant (type, attrs);
+ }
It seems odd to propagate this attribute to a larger type after promotion.
But I agree we want to keep it in the case where we return the same type.
The reasoning for keeping it after promotion is that if the attribute is
applied to short, say, and the result of arithmetic on such
attributed-short (promoted to int) is stored in a char, there should be a
warning for that truncation to char.
In principle the attribute could be associated internally with the width
of the type it was originally applied to (and still preserved across
promotions), so that it's actually "warn for truncation to narrower than
that width". But since all the likely use cases are on 64-bit types such
as time_t and off_t, it seemed simpler just to preserve the attribute
without associating with a width, at the cost of possible excess warnings
if it gets applied to a narrow type.
We might reject/ignore applying the attribute to a type that promotes to
a wider type, to avoid needing to get the semantics right for such
unlikely uses.
Jason