public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99176] New: GCC rejects const_cast of null pointer in constant expressions
@ 2021-02-19 23:11 richard-gccbugzilla at metafoo dot co.uk
  2021-02-19 23:21 ` [Bug c++/99176] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2021-02-19 23:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99176
           Summary: GCC rejects const_cast of null pointer in constant
                    expressions
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

GCC rejects:

constexpr const int *p = nullptr;
constexpr int *q = const_cast<int*>(p);

saying:

<source>:2:20: error: conversion of 'const int*' null pointer to 'int*' is not
a constant expression
    2 | constexpr int *q = const_cast<int*>(p);
      |                    ^~~~~~~~~~~~~~~~~~~

I don't think any such rule exists, and other compilers accept. This only
appears to affect const_casts of null pointers; non-null pointer const casts
seem to work OK. Perhaps GCC thinks that this is a reinterpret_cast / cast from
void* or something like that?

It looks like this regressed between GCC 6 and GCC 7.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-09 22:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 23:11 [Bug c++/99176] New: GCC rejects const_cast of null pointer in constant expressions richard-gccbugzilla at metafoo dot co.uk
2021-02-19 23:21 ` [Bug c++/99176] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
2021-02-19 23:22 ` mpolacek at gcc dot gnu.org
2021-02-22 23:24 ` mpolacek at gcc dot gnu.org
2021-02-25 21:29 ` cvs-commit at gcc dot gnu.org
2021-02-25 21:32 ` [Bug c++/99176] [8/9/10 " mpolacek at gcc dot gnu.org
2021-04-09 22:42 ` cvs-commit at gcc dot gnu.org
2021-04-09 22:43 ` mpolacek at gcc dot gnu.org

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).