[Bug libstdc++/78991] New: std::sort and std::unique can not use std::function with clang++ -std=c++14

daiw at gmx dot net gcc-bugzilla@gcc.gnu.org
Wed Jan 4 20:35:00 GMT 2017


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

            Bug ID: 78991
           Summary: std::sort and std::unique can not use std::function
                    with clang++ -std=c++14
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daiw at gmx dot net
  Target Milestone: ---

The following two minimal examples both compile with

clang++ -std=c++11 main.cpp

but do not with

clang++ -std=c++14 main.cpp


// example 1
#include <algorithm>
#include <functional>
#include <vector>
int main()
{
  std::vector<int> xs = {0,1,2};
  std::function<bool(int x, int y)> cmp = [](int x, int y)
    { return x < y; };
  std::sort(std::begin(xs), std::end(xs), cmp);
}


// example 2
#include <algorithm>
#include <functional>
#include <vector>
int main()
{
  std::vector<int> xs = {0,1,2};
  std::function<bool(int x, int y)> p = [](int x, int y)
    { return x == y; };
  std::unique(std::begin(xs), std::end(xs), p);
}


The error message looks like this:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/algorithm:61:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_algobase.h:71:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/predefined_ops.h:123:31:
error: indirection requires pointer operand ('int' invalid)
        { return bool(_M_comp(*__it1, *__it2)); }


The used version is the default one from the package manager in Ubuntu 16.04:
clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin


More information about the Gcc-bugs mailing list