public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114602] New: Compilcation failure when using a user-defined function which name is same as a posix function
@ 2024-04-05 12:15 zwuis at outlook dot com
  2024-04-05 13:13 ` [Bug libstdc++/114602] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: zwuis at outlook dot com @ 2024-04-05 12:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114602

            Bug ID: 114602
           Summary: Compilcation failure when using a user-defined
                    function which name is same as a posix function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zwuis at outlook dot com
  Target Milestone: ---

Code:
```
#include <algorithm>
#include <cstring>

struct foo {};
bool bcmp(foo, foo) { return false; }

int main() {
    foo* ptr = nullptr;
    std::sort(ptr, ptr, bcmp);
}
```
Compiler option: -std=c++17 -v

Compiler output:

Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-13.2.0/bin/g++
Target: x86_64-linux-gnu
Configured with: ../gcc-13.2.0/configure
--prefix=/opt/compiler-explorer/gcc-build/staging
--enable-libstdcxx-backtrace=yes --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,m2 --enable-ld=yes
--enable-gold=yes --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc--binutils-2.40
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (Compiler-Explorer-Build-gcc--binutils-2.40) 
COLLECT_GCC_OPTIONS='-fdiagnostics-color=always' '-g' '-o' '/app/output.s'
'-masm=intel' '-S' '-std=c++17' '-v' '-shared-libgcc' '-mtune=generic'
'-march=x86-64' '-dumpdir' '/app/'

/opt/compiler-explorer/gcc-13.2.0/bin/../libexec/gcc/x86_64-linux-gnu/13.2.0/cc1plus
-quiet -v -imultiarch x86_64-linux-gnu -iprefix
/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -std=c++17 -version
-fdiagnostics-color=always -o /app/output.s
GNU C++17 (Compiler-Explorer-Build-gcc--binutils-2.40) version 13.2.0
(x86_64-linux-gnu)
        compiled by GNU C version 11.4.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/include"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/x86_64-linux-gnu"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/backward"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/include"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed/x86_64-linux-gnu"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed"
ignoring nonexistent directory
"/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/x86_64-linux-gnu

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/backward

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/include

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed/x86_64-linux-gnu

/opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed
 /usr/local/include
 /opt/compiler-explorer/gcc-13.2.0/bin/../lib/gcc/../../include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
Compiler executable checksum: 1f79f5ecde65b98f00fc1524c141d88e
<source>: In function 'int main()':
<source>:9:14: error: no matching function for call to 'sort(foo*&, foo*&,
<unresolved overloaded function type>)'
    9 |     std::sort(ptr, ptr, bcmp);
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/algorithm:61,
                 from <source>:1:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/stl_algo.h:4851:5:
note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4851 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/stl_algo.h:4851:5:
note:   template argument deduction/substitution failed:
<source>:9:14: note:   candidate expects 2 arguments, 3 provided
    9 |     std::sort(ptr, ptr, bcmp);
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/stl_algo.h:4882:5:
note: candidate: 'template<class _RAIter, class _Compare> void
std::sort(_RAIter, _RAIter, _Compare)'
 4882 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/stl_algo.h:4882:5:
note:   template argument deduction/substitution failed:
<source>:9:14: note:   couldn't deduce template parameter '_Compare'
    9 |     std::sort(ptr, ptr, bcmp);
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/algorithm:73:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:292:1:
note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator,
class _Compare>
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
_Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:292:1:
note:   template argument deduction/substitution failed:
<source>:9:14: note:   candidate expects 4 arguments, 3 provided
    9 |     std::sort(ptr, ptr, bcmp);
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:296:1:
note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator>
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
_RandomAccessIterator __last);
      | ^~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:296:1:
note:   template argument deduction/substitution failed:
In file included from
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:15:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/execution_defs.h: In
substitution of 'template<class _ExecPolicy, class _Tp> using
__pstl::__internal::__enable_if_execution_policy = typename
std::enable_if<__pstl::execution::v1::is_execution_policy<typename
std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value,
_Tp>::type [with _ExecPolicy = foo*&; _Tp = void]':
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/glue_algorithm_defs.h:296:1:
  required by substitution of 'template<class _ExecutionPolicy, class
_RandomAccessIterator>
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)
[with _ExecutionPolicy = foo*&; _RandomAccessIterator = foo*]'
<source>:9:14:   required from here
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/pstl/execution_defs.h:150:7:
error: no type named 'type' in 'struct std::enable_if<false, void>'
  150 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also see https://godbolt.org/z/dTWK17v51 .

Note that `#include <cstring>` is required to reproduce the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/114602] Compilcation failure when using a user-defined function which name is same as a posix function
  2024-04-05 12:15 [Bug libstdc++/114602] New: Compilcation failure when using a user-defined function which name is same as a posix function zwuis at outlook dot com
@ 2024-04-05 13:13 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-05 13:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114602

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a longstanding issue that glibc headers expose all APIs when included
from C++ code.

You can either cast the function pointer to the right type:

    std::sort(ptr, ptr, static_cast<bool(*)(foo, foo)>(bcmp));

or use a lambda expression:

    std::sort(ptr, ptr, [](foo l, foo r) { return bcmp(l, r); });

*** This bug has been marked as a duplicate of bug 11196 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-05 13:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 12:15 [Bug libstdc++/114602] New: Compilcation failure when using a user-defined function which name is same as a posix function zwuis at outlook dot com
2024-04-05 13:13 ` [Bug libstdc++/114602] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).