This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61105] [constexpr] accepts-invalid with new-expression in constant expression
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 12 May 2016 23:22:48 +0000
- Subject: [Bug c++/61105] [constexpr] accepts-invalid with new-expression in constant expression
- Auto-submitted: auto-generated
- References: <bug-61105-4 at http dot gcc dot gnu dot org/bugzilla/>
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 ();
$