diff options
author | Jason Merrill <jason@redhat.com> | 2024-02-12 18:24:00 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-05-01 11:44:13 -0400 |
commit | c3bc2787b8beb7aae67fdf2a7f7271a9a4edca7c (patch) | |
tree | cf9589f3453380733238ab09459e55d19f0eeb33 /gcc/cp | |
parent | 0695aba3e987f4bb06c95f29ff90a8a3234e1507 (diff) | |
download | gcc-c3bc2787b8beb7aae67fdf2a7f7271a9a4edca7c.zip gcc-c3bc2787b8beb7aae67fdf2a7f7271a9a4edca7c.tar.gz gcc-c3bc2787b8beb7aae67fdf2a7f7271a9a4edca7c.tar.bz2 |
c++: const void* memchr [PR113706]
The C++ standard specifies that the <string.h> functions have const and
non-const overloads, unlike C's single function with const argument and
non-const return. Many systems don't actually implement this, but only add
an overload with non-const argument, so both end up having non-const return.
Solaris <string.h> does what the standard says, but we were penalizing it by
not recognizing the const overload as the built-in memchr.
PR c++/113706
gcc/cp/ChangeLog:
* decl.cc (decls_match): Handle memchr return type being
const-qualified.
gcc/testsuite/ChangeLog:
* g++.dg/opt/const-builtin1.C: New test.
* c-c++-common/pr103798-2.c: Remove xfail.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/decl.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index d88e069..df85533 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -1156,6 +1156,16 @@ decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */) tree r2 = fndecl_declared_return_type (olddecl); tree r1 = fndecl_declared_return_type (newdecl); + /* For memchr et al, allow const void* return type (as specified by C++) + when we expect void* (as in C). */ + if (DECL_IS_UNDECLARED_BUILTIN (olddecl) + && DECL_EXTERN_C_P (olddecl) + && !same_type_p (r1, r2) + && TREE_CODE (r1) == POINTER_TYPE + && TREE_CODE (r2) == POINTER_TYPE + && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2))) + r2 = r1; + tree p1 = TYPE_ARG_TYPES (f1); tree p2 = TYPE_ARG_TYPES (f2); |