GithubHelp home page GithubHelp logo

Comments (4)

jonahgraham avatar jonahgraham commented on July 24, 2024

Thanks for the bug report.

This code does not compile for me in g++, I get:

$ g++ -c a.cc
a.cc: In function ‘bool isUpper(const string&)’:
a.cc:7:55: error: no matching function for call to ‘find_if(std::__cxx11::basic_string<char>::const_iterator, std::__cxx11::basic_string<char>::const_iterator, <unresolved overloaded function type>)’
    7 |   return std::find_if(s.begin(), s.end(), std::islower) == s.end();
      |                                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from a.cc:2:
/usr/include/c++/10/bits/stl_algo.h:3925:5: note: candidate: ‘template<class _IIter, class _Predicate> _IIter std::find_if(_IIter, _IIter, _Predicate)’
 3925 |     find_if(_InputIterator __first, _InputIterator __last,
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:3925:5: note:   template argument deduction/substitution failed:
a.cc:7:55: note:   couldn’t deduce template parameter ‘_Predicate’
    7 |   return std::find_if(s.begin(), s.end(), std::islower) == s.end();
      |                                                       ^

Which variant of C++ are you using? CDT is missing some support for C++17 and newer standards.

from cdt.

mbooth101 avatar mbooth101 commented on July 24, 2024

The code does not compile even if you pass -std=c++17 or -std=c++20 (I'm using GCC 12) -- if you ask CDT to open the declaration, it seems to be trying to resolve bool std::islower(char, locale) instead of int std::islower(int)

Maybe this is what the "unresolved overloaded function type" error from GCC is trying to tell me, but I'm not really a C++ guy and I find C++ errors a bit impenetrable :-)

However passing a lambda instead seems to make it compile just fine:

return std::find_if(s.begin(), s.end(), [](unsigned char c) {return std::islower(c);}) == s.end(); 

And indeed CDT is also happy with it as a lambda, so CDT seems consistent with GCC here.

Removing the std prefix presumably causes it to use the int islower(int) libc function from the C header ctype.h

Maybe @Sporking can tell us more about their compiler version and the compiler flags they are using....

from cdt.

Sporking avatar Sporking commented on July 24, 2024

After doing more research, I think that this was the problem:

https://stackoverflow.com/questions/7131858/stdtransform-and-toupper-no-matching-function

Specifically, there is more than one 'std::islower' in the C++ standard library, and when its address is taken without function arguments to disambiguate, the compiler can't decide which one is meant.

I think that the reason that my code was able to successfully compile on Visual Studio 2017 is because they were probably including a different set of C++ standard header files in their includes than the header files I was using with Eclipse (which were from the Cygwin gcc 11 release). So when I compiled, it probably only included one definition of std::islower instead of two that were included when I used Eclipse with gcc header files.

Thanks for your investigations. I am closing this bug, since at the moment I think that Eclipse was probably behaving correctly.

from cdt.

jonahgraham avatar jonahgraham commented on July 24, 2024

Thanks @Sporking for reporting back on your resolution and closing this issue.

from cdt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.