Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< --
Since Jakub's P2795R5 work removes the initial clobber from constructors, let's add a clobber for new of all non-empty classes. gcc/cp/ChangeLog: * init.cc (build_new_1): Clobber classes. gcc/testsuite/ChangeLog: * g++.dg/analyzer/pr97116.C: Adjust diagnostic. * g++.dg/warn/Warray-bounds-20.C: Likewise. --- gcc/cp/init.cc | 4 +--- gcc/testsuite/g++.dg/analyzer/pr97116.C | 5 ++--- gcc/testsuite/g++.dg/warn/Warray-bounds-20.C | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index c950c363f59..3fe476d7eec 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -3566,9 +3566,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, = (std_placement && flag_lifetime_dse > 1 && !processing_template_decl && !is_empty_type (elt_type) - && !*init - && (!CLASS_TYPE_P (elt_type) - || type_has_non_user_provided_default_constructor (elt_type))); + && (!*init || CLASS_TYPE_P (elt_type))); /* In the simple case, we can stop now. */ pointer_type = build_pointer_type (type); diff --git a/gcc/testsuite/g++.dg/analyzer/pr97116.C b/gcc/testsuite/g++.dg/analyzer/pr97116.C index 1c404c2ceb2..06ee8623f43 100644 --- a/gcc/testsuite/g++.dg/analyzer/pr97116.C +++ b/gcc/testsuite/g++.dg/analyzer/pr97116.C @@ -3,7 +3,7 @@ struct foo { - foo (int i) : m_i (i) {} // { dg-message "argument 'this' of 'foo::foo\\(int\\)' must be non-null" "note" } + foo (int i) : m_i (i) {} int get () const { return m_i; } // { dg-message "argument 'this' of '\[^\n\]*' must be non-null" "note" } @@ -15,8 +15,7 @@ struct foo void test_1 (void) { - foo *p = new(NULL) foo (42); // { dg-warning "non-null expected" "warning" } - // { dg-message "argument 'this'( \\(\[^\n\]*\\))? NULL where non-null expected" "final event" { target *-*-* } .-1 } + foo *p = new(NULL) foo (42); // { dg-warning "dereference of NULL" "warning" } } int test_2 (void) diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C index 5fc55293074..36f8046fed7 100644 --- a/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C @@ -39,7 +39,7 @@ void warn_derived_ctor_access_new_decl () // { dg-message "at offset 1 into object 'a' of size 20" "LP64 note" { target ilp32} .-1 } char *p = a; ++p; - D1 *q = new (p) D1; + D1 *q = new (p) D1; // { dg-warning "-Warray-bounds" } sink (q); } @@ -47,7 +47,7 @@ void warn_derived_ctor_access_new_alloc () { char *p = (char*)operator new (sizeof (D1)); // { dg-message "at offset 1 into object of size \\d+ allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" } ++p; - D1 *q = new (p) D1; + D1 *q = new (p) D1; // { dg-warning "-Warray-bounds" } sink (q); } base-commit: b8af1b3a00249eceacf53444cdb339761eeb9f02 -- 2.51.0