[gcc r13-9580] c++: Diagnose earlier non-static data members with cv containing class type [PR116108]
Jakub Jelinek
jakub@gcc.gnu.org
Wed Apr 23 13:09:11 GMT 2025
https://gcc.gnu.org/g:28646ac56a32556a53c39750dbe05ffa6e3c4458
commit r13-9580-g28646ac56a32556a53c39750dbe05ffa6e3c4458
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Dec 17 10:13:24 2024 +0100
c++: Diagnose earlier non-static data members with cv containing class type [PR116108]
In r10-6457 aka PR92593 fix a check has been added to reject
earlier non-static data members with current_class_type in templates,
as the deduction then can result in endless recursion in reshape_init.
It fixed the
template <class T>
struct S { S s = 1; };
S t{2};
crashes, but as the following testcase shows, didn't catch when there
are cv qualifiers on the non-static data member.
Fixed by using TYPE_MAIN_VARIANT.
2024-12-17 Jakub Jelinek <jakub@redhat.com>
PR c++/116108
gcc/cp/
* decl.cc (grokdeclarator): Pass TYYPE_MAIN_VARIANT (type)
rather than type to same_type_p when checking if the non-static
data member doesn't have current class type.
gcc/testsuite/
* g++.dg/cpp1z/class-deduction117.C: New test.
(cherry picked from commit 88bfee560681d8248b89f130ada249e35ee2e344)
Diff:
---
gcc/cp/decl.cc | 3 ++-
gcc/testsuite/g++.dg/cpp1z/class-deduction117.C | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 8f902fb1d114..e49641680231 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -14362,7 +14362,8 @@ grokdeclarator (const cp_declarator *declarator,
}
else if (!staticp
&& ((current_class_type
- && same_type_p (type, current_class_type))
+ && same_type_p (TYPE_MAIN_VARIANT (type),
+ current_class_type))
|| (!dependent_type_p (type)
&& !COMPLETE_TYPE_P (complete_type (type))
&& (!complete_or_array_type_p (type)
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction117.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction117.C
new file mode 100644
index 000000000000..8ab91018377f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction117.C
@@ -0,0 +1,7 @@
+// PR c++/116108
+// { dg-do compile { target c++11 } }
+template <class T>
+struct S { const S s = 1; }; // { dg-error "field 's' has incomplete type 'const S<T>'" }
+S t{2}; // { dg-error "invalid use of template-name 'S' without an argument list" "" { target c++14_down } }
+// { dg-error "class template argument deduction failed" "" { target c++17 } .-1 }
+// { dg-error "no matching function for call to 'S\\\(int\\\)'" "" { target c++17 } .-2 }
More information about the Gcc-cvs
mailing list