On 11/21/23 17:51, Jakub Jelinek wrote:
On Tue, Nov 21, 2023 at 11:19:56PM +0100, Jakub Jelinek wrote:
+         error_at (location, "%<static_assert%> message must be a string "
+                             "literal or object with %<size%> and "
+                             "%<data%> members");

Let's print the type of the message as well.

so add " while it has type %qT", TREE_TYPE (message) or something else?

Now in patch form (except for the removal of warning_at for now):

+  if (TREE_CODE (message) != STRING_CST
+      && !type_dependent_expression_p (message))
+    {
+      message_sz
+       = finish_class_member_access_expr (message,
+                                          get_identifier ("size"),
+                                          false, tf_none);
+      message_data
+       = finish_class_member_access_expr (message,
+                                          get_identifier ("data"),
+                                          false, tf_none);
+      if (message_sz == error_mark_node || message_data == error_mark_node)
+       {
+         error_at (location, "%<static_assert%> message must be a string "
+                             "literal or object with %<size%> and "
+                             "%<data%> members while it has type %qT",

Actually, let's go back to the previous message, but change the tf_nones above to 'complain' so that we see those errors and then this explanation. Likewise with the conversion checks later in the function.

+                             TREE_TYPE (message));
+         return;
+       }
+      releasing_vec size_args, data_args;
+      message_sz = finish_call_expr (message_sz, &size_args, false, false,
+                                    tf_warning_or_error);
+      message_data = finish_call_expr (message_data, &data_args, false, false,
+                                      tf_warning_or_error);

Can use 'complain' instead of tf_warning_or_error here, too.

+      if (message_sz == error_mark_node || message_data == error_mark_node)
+       return;
+      if (tree s
+         = cp_get_callee_fndecl_nofold (extract_call_expr (message_sz)))
+       if (!DECL_DECLARED_CONSTEXPR_P (s))
+         warning_at (location, 0, "%qD used in %<static_assert%> message "
+                                  "is not %<constexpr%>", s);

I don't think we need this check, it should be covered by the later
constant-expression checks.

If the static_assert condition is true, we won't diagnose anything then.
clang++ there incorrectly errors, but I thought a warning could be useful
to users.  Perhaps it could warn only if the condition is true?

I don't think the extra warning is that useful, especially with no flag to suppress it; we specifically decided not to require the message to be constant if the condition is true, and involving a non-constexpr function is just one example of how it might not be constant.

Jason

Reply via email to