diff options
author | Simon Martin <simon@nasilyan.com> | 2025-02-11 15:59:02 +0100 |
---|---|---|
committer | Simon Martin <simon@nasilyan.com> | 2025-02-11 15:59:02 +0100 |
commit | c74e7f651a014d59631361bcc9be05d797928c5c (patch) | |
tree | 1327627382391664163f3f087e8ccdad1966ccd0 /gcc/lto/lto-lang.cc | |
parent | e8c5013b6b7820d77edc45d04e634d49b20c05ce (diff) | |
download | gcc-c74e7f651a014d59631361bcc9be05d797928c5c.zip gcc-c74e7f651a014d59631361bcc9be05d797928c5c.tar.gz gcc-c74e7f651a014d59631361bcc9be05d797928c5c.tar.bz2 |
c++: Reject cdtors and conversion operators with a single * as return type [PR118304, PR118306]
We currently accept the following constructor declaration (clang, EDG
and MSVC do as well), and ICE on the destructor declaration
=== cut here ===
struct A {
*A ();
~A () = default;
};
=== cut here ===
The problem is that we end up in grokdeclarator with a cp_declarator of
kind cdk_pointer but no type, and we happily go through (if we have a
reference instead we eventually error out trying to form a reference to
void).
This patch makes sure that grokdeclarator errors out and strips the
invalid declarator when processing a cdtor (or a conversion operator
with no return type specified) with a declarator representing a pointer
or a reference type.
PR c++/118306
PR c++/118304
gcc/cp/ChangeLog:
* decl.cc (maybe_strip_indirect_ref): New.
(check_special_function_return_type): Take declarator as input.
Call maybe_strip_indirect_ref and error out if it returns true.
(grokdeclarator): Update call to
check_special_function_return_type.
gcc/testsuite/ChangeLog:
* g++.old-deja/g++.jason/operator.C: Adjust bogus test
expectation (char** vs char*).
* g++.dg/parse/constructor4.C: New test.
* g++.dg/parse/constructor5.C: New test.
* g++.dg/parse/conv_op2.C: New test.
* g++.dg/parse/default_to_int.C: New test.
Diffstat (limited to 'gcc/lto/lto-lang.cc')
0 files changed, 0 insertions, 0 deletions