From: Jason Merrill Date: Mon, 5 Aug 2024 19:04:05 +0000 (-0400) Subject: c++: zero-init and class nttp [PR94568] X-Git-Tag: basepoints/gcc-16~6794 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=352c21c8a22a48d34cbd2fbfe398ee12c0a1d681;p=thirdparty%2Fgcc.git c++: zero-init and class nttp [PR94568] A zero-initializer should not reflect the constness of what it's initializing, as it does not for initializers with different syntax. This does have mangling implications for rare C++20 code, but it seems infeasable to make the mangling depend on -fabi-version while fixing the semantic bug, and C++20 is still experimental anyway. PR c++/94568 gcc/cp/ChangeLog: * init.cc (build_zero_init_1): Call cv_unqualified. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class36.C: Remove xfail. * g++.dg/cpp2a/nontype-class37.C: Remove xfail. * g++.dg/cpp1z/nontype-auto26.C: New test. --- diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index de82152bd1d..20373d26988 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -173,6 +173,9 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, gcc_assert (nelts == NULL_TREE || TREE_CODE (nelts) == INTEGER_CST); + /* An initializer is unqualified. */ + type = cv_unqualified (type); + if (type == error_mark_node) ; else if (static_storage_p && zero_init_p (type)) diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C new file mode 100644 index 00000000000..9abe54ed974 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto26.C @@ -0,0 +1,29 @@ +// PR c++/94568 +// { dg-do compile { target c++20 } } + +struct A; +typedef int A::*MemPtr; + +struct B { MemPtr p; }; + +static constexpr MemPtr mp { }; + +template struct X { }; + +typedef X XB; +typedef X XB; + +struct C { int a[2]; }; +template struct D { }; + +constexpr const int i0 = 0; +constexpr const int i_{ }; + +static_assert (i0 == i_); + +// typedef D DC01; +// typedef D DC01; +typedef D DC01; + +// { dg-final { scan-assembler "_Z1f1DIXtl1CtlA2_iLi0ELi1EEEEE" } } +void f(DC01) {} diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C index 8371eb96621..2e6d76cd43a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class36.C @@ -59,7 +59,7 @@ typedef X XB00p; typedef X XB00p; typedef X XB00p; typedef X XB00p; -typedef X XB00p; // { dg-bogus "conflicting declaration" "pr94568" { xfail *-*-* } } +typedef X XB00p; // { dg-bogus "conflicting declaration" "pr94568" } static const constexpr MemFuncPtr mfp0 = { 0 }; static const constexpr MemFuncPtr mfpn = { nullptr }; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C index f5e9826d243..dc054a9939a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class37.C @@ -77,4 +77,4 @@ typedef D DC01; typedef D DC01; typedef D DC01; typedef D DC01; -typedef D DC01; // { dg-bogus "conflicting declaration" "pr94567" { xfail *-*-* } } +typedef D DC01; // { dg-bogus "conflicting declaration" "pr94568" }