+2017-11-13 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ Remove the null check from placement new in all modes
+ * init.c (build_new_1): Don't do a null check for
+ a namespace-scope non-replaceable placement new
+ in any mode unless -fcheck-new is provided.
+
2017-11-07 Boris Kolpackov <boris@codesynthesis.com>
* Make-lang.in (CP_PLUGIN_HEADERS): Add operators.def since included
static bool
std_placement_new_fn_p (tree alloc_fn)
{
- if ((cxx_dialect > cxx14) && DECL_NAMESPACE_SCOPE_P (alloc_fn))
+ if (DECL_NAMESPACE_SCOPE_P (alloc_fn))
{
tree first_arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (alloc_fn)));
if ((TREE_VALUE (first_arg) == ptr_type_node)
// PR c++/35878
// { dg-do compile }
// { dg-options "-O2 -std=gnu++11 -fdump-tree-optimized" }
-// { dg-final { scan-tree-dump-times "v_\[0-9]+\\(D\\) \[=!]= 0" 1 "optimized" } }
+// { dg-final { scan-tree-dump-not "v_\[0-9]+\\(D\\) \[=!]= 0" "optimized" } }
#include <new>
#include <utility>
--- /dev/null
+// PR c++/35878
+// { dg-do compile }
+// { dg-options "-O2 -std=gnu++11 -fcheck-new -fdump-tree-optimized" }
+// { dg-final { scan-tree-dump-times "v_\[0-9]+\\(D\\) \[=!]= 0" 1 "optimized" } }
+
+#include <new>
+#include <utility>
+
+struct s1{
+ int a;
+ int b;
+ int c;
+};
+
+void f1 (s1 * v, s1&& s)
+{
+ new (v) s1(std::move(s));
+}
+
+void f2 (s1 * v, s1&& s)
+{
+ *v = std::move(s);
+}
// { dg-do run }
+/* { dg-options "-fcheck-new" } */
typedef __SIZE_TYPE__ size_t;
/* { dg-do compile } */
-/* { dg-options "-O -fno-tree-vrp -fdump-tree-forwprop1" } */
+/* { dg-options "-O -fcheck-new -fno-tree-vrp -fdump-tree-forwprop1" } */
#include <new>
return v.a[2];
}
-/* -std=c++17 and above doesn't emit operator new () != NULL, so there is
- nothing to fold anymore. */
-/* { dg-final { scan-tree-dump "Replaced .* != 0B. with .1" "forwprop1" { target c++14_down } } } */
+/* GCC 8 emits operator new () != NULL with -fcheck-new. */
+/* { dg-final { scan-tree-dump "Replaced .* != 0B. with .1" "forwprop1" } } */
/* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-ccp1-details" } */
+/* { dg-options "-O -fcheck-new -fdump-tree-ccp1-details" } */
extern "C" void abort (void);
inline void *operator new (__SIZE_TYPE__, void *__p) throw () { return __p; }
return *(int *)&f;
}
-/* -std=c++17 and above doesn't emit operator new () != NULL, so there is
- nothing to fold anymore. */
-/* { dg-final { scan-tree-dump "Folded into: if \\\(1 != 0\\\)" "ccp1" { target c++14_down } } } */
+/* GCC 8 emits operator new () != NULL with -fcheck-new. */
+/* { dg-final { scan-tree-dump "Folded into: if \\\(1 != 0\\\)" "ccp1" } } */