public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110348] [C++26] P2741R3 - User-generated static_assert messages
Date: Thu, 24 Aug 2023 12:28:04 +0000	[thread overview]
Message-ID: <bug-110348-4-eKduGtApWj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110348-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110348

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> (In reply to Jonathan Wakely from comment #5)
> > I agree with your WIP patch. The requirements for data() and size() to be
> > constant expressions are in p11 (11.2) which only apply if the static
> > assertions fails.
> 
> In other words, I think the paper is clear and clang is wrong here.
> 
> Although arguably what clang does is more useful. I'm not sure why you'd
> want to use a non-constexpr size() or data() that only compiles as long as
> the static assertion passes. It means you won't find out that your
> user-generated message can't actually be printed until you run on a target
> where the assertion fails.

Sure, if the standard is changed such that size() and data() must be constexpr,
it would be nice to check it.  Without full evaluation one can't guarantee it
will
be a constant expression and there could be tons of other reasons why it isn't
constant expression (say it returns some class and conversion operator isn't
constexpr, or it throws, or has asm and many other reasons).

For the M.data () not being a constant expression, it depends on the exact
wording as well.  Either the standard could drop the requirement that it is a
core constant expression altogether, then e.g. nothing will require that
(M.data (), 0) is constant expression when M.size () is 0.  Or it could say
that (M.data (), 0) is an integer constant expression, then one can verify
that, and then quietly try if M.data () is a constant expression; if it is, it
can grab the message from it using say GCC's c_getstr if it works.  If it
isn't, it would need to evaluate it character by character.

BTW, there is a third difference between my latest patch and clang++
implementation.
They reject static_assert (false, "foo"_myd); which I have in the testcase. 
IMHO
"foo"_myd doesn't match the syntactic requirements of unevaluated-string as the
https://eel.is/c++draft/dcl.pre#10 wording says, because unevaluated-string
non-terminal is string-literal with some extra rules, while
user-defined-literal is some other non-terminal.  And as I've tried to show in
the testcase, a constexpr operator ""
can return something on which .size () / .data () can be called and can satisfy
the requirements.

  parent reply	other threads:[~2023-08-24 12:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 16:25 [Bug c++/110348] New: " mpolacek at gcc dot gnu.org
2023-06-21 22:47 ` [Bug c++/110348] " pinskia at gcc dot gnu.org
2023-08-23 16:46 ` jakub at gcc dot gnu.org
2023-08-23 20:23 ` jakub at gcc dot gnu.org
2023-08-24 11:22 ` jakub at gcc dot gnu.org
2023-08-24 11:56 ` redi at gcc dot gnu.org
2023-08-24 12:10 ` redi at gcc dot gnu.org
2023-08-24 12:19 ` redi at gcc dot gnu.org
2023-08-24 12:28 ` jakub at gcc dot gnu.org [this message]
2023-09-12 11:30 ` corentinjabot at gmail dot com
2023-09-12 12:03 ` jakub at gcc dot gnu.org
2023-09-12 12:23 ` jakub at gcc dot gnu.org
2023-09-12 13:14 ` jakub at gcc dot gnu.org
2023-09-12 15:20 ` jason at gcc dot gnu.org
2023-09-12 15:21 ` jason at gcc dot gnu.org
2023-11-23  8:27 ` cvs-commit at gcc dot gnu.org
2023-11-23  8:42 ` jakub at gcc dot gnu.org
2023-11-23  9:38 ` corentinjabot at gmail dot com
2023-11-23  9:58 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110348-4-eKduGtApWj@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).