This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/61105] [constexpr] accepts-invalid with new-expression in constant expression


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|6.0                         |6.1.0, 7.0

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
With my patch for bug 60760 GCC rejects the original test case:

$ cat xx.cpp && /build/gcc-60760/gcc/xgcc -B /build/gcc-60760/gcc -S -Wall
-Wextra -Wpedantic -o/dev/null xx.cpp
using size_t = decltype (sizeof (0));
constexpr void *operator new (size_t, int*) noexcept { return nullptr; }
constexpr int *p = new (nullptr) int;
xx.cpp:3:34: error: invalid conversion involving a null pointer
 constexpr int *p = new (nullptr) int;
                                  ^~~

But the patch doesn't fix the underlying problem that GCC accepts a placement
new expression in a constexpr function.  It's evident from the fact that the
following modified test case that avoids using the null pointer is still
accepted:

$ cat xx.cpp && /build/gcc-60760/gcc/xgcc -B /build/gcc-60760/gcc -S -Wall
-Wextra -Wpedantic -o/dev/null xx.cpp
constexpr void *operator new (__SIZE_TYPE__, void *p) noexcept { return p; }

constexpr int f ()
{
  int i = 0;
  int *p = new (&i) int (1);
  return *p;
}

constexpr int i = f ();
$

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]