-Wsizeof-array-div offers a way to suppress the warning by wrapping
the second operand of the division in parens:
sizeof (samplesBuffer) / (sizeof(unsigned char))
but this doesn't work in a template, because we fail to propagate
the suppression bits. Do it, then.
The finish_parenthesized_expr hunk is not needed because suppress_warning
isn't very fine-grained. But I think it makes sense to be explicit and
not rely on OPT_Wparentheses also suppressing OPT_Wsizeof_array_div.
PR c++/114983
gcc/cp/ChangeLog:
* pt.cc (tsubst_expr) <case SIZEOF_EXPR>: Use copy_warning.
* semantics.cc (finish_parenthesized_expr): Also suppress
-Wsizeof-array-div.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wsizeof-array-div3.C: New test.
TREE_READONLY (r) = 1;
}
SET_EXPR_LOCATION (r, EXPR_LOCATION (t));
+ copy_warning (r, t);
}
RETURN (r);
}
/* This inhibits warnings in maybe_warn_unparenthesized_assignment
and c_common_truthvalue_conversion. */
suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
+ /* And maybe_warn_sizeof_array_div. */
+ suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
}
if (TREE_CODE (expr) == OFFSET_REF
--- /dev/null
+// PR c++/114983
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wsizeof-array-div" }
+
+using size_t = decltype (sizeof (0));
+unsigned int samplesBuffer[40];
+
+template <typename T>
+constexpr inline size_t fn1()
+{
+ return ((sizeof(samplesBuffer)) / (sizeof(T))); // { dg-bogus "expression does not compute" }
+}
+
+template <typename T>
+constexpr inline size_t fn2()
+{
+ return ((sizeof(samplesBuffer)) / sizeof(T)); // { dg-warning "expression does not compute" }
+}
+
+size_t
+g ()
+{
+ auto sz = sizeof (samplesBuffer) / (sizeof(unsigned char));
+ sz += fn1<unsigned char>();
+ sz += fn2<unsigned char>(); // { dg-message "required from here" }
+ return sz;
+}