This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR78991 make __gnu_cxx::__ops constructors explicit


Hi Jonathan,

On 06/01/17 12:40, Jonathan Wakely wrote:
This solves a problem when using libstdc++ with Clang, due to Clang
more eagerly instantiating constexpr function templates during
argument deduction. G++ has some shortcuts to avoid this problem, but
Clang doesn't, and it's not clear that it's strictly speaking a bug in
Clang or if it's following the standard. By making these constructors
explicit we stop them being considered by overload resolution for
copying these functors, which stops us ending up back in the
std::function SFINAE checks.

I'm also using _GLIBCXX_MOVE to turn some internal copies into moves,
because otherwise using something like std::function with <algorithm>
results in a number of potentially expensive copies.

    PR libstdc++/78991
    * include/bits/predefined_ops.h (_Iter_comp_iter, _Iter_comp_val)
    (_Val_comp_iter, _Iter_equals_val, _Iter_pred, _Iter_comp_to_val)
    (_Iter_comp_to_iter, _Iter_negate): Make constructors explicit and
    move function objects.
    (__iter_comp_iter, __iter_comp_val, __val_comp_iter, __pred_iter)
    (__iter_comp_val, __iter_comp_iter, __negate): Move function objects.
    * testsuite/25_algorithms/sort/78991.cc: New test.

Tested powerpc64le-linux, committed to trunk.

I'll backport  the 'explicit' constructors (but not the _GLIBCXX_MOVE
changes) to the branches too.


I see this test fail on the GCC 5 branch on arm and aarch64 (error message pasted below).
Does the test need a gnu++11 guard or something on the branch?

Thanks,
Kyrill

$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:28:16: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
   function() = default;
                ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:30:40: error: 'result_of_t' in namespace 'std' does not name a template type
   template<typename F, typename = std::result_of_t<F&(int, int)>>
                                        ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:30:51: error: expected '>' before '<' token
   template<typename F, typename = std::result_of_t<F&(int, int)>>
                                                   ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:31:17: error: expected unqualified-id before '{' token
     function(F) { }
                 ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc: In function 'int main()':
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:38:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   int a[2]{ 2, 1 };
           ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:39:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   std::sort(a, a+2, function{});
                             ^
compiler exited with status 1
output is:
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:28:16: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11
   function() = default;
                ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:30:40: error: 'result_of_t' in namespace 'std' does not name a template type
   template<typename F, typename = std::result_of_t<F&(int, int)>>
                                        ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:30:51: error: expected '>' before '<' token
   template<typename F, typename = std::result_of_t<F&(int, int)>>
                                                   ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:31:17: error: expected unqualified-id before '{' token
     function(F) { }
                 ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc: In function 'int main()':
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:38:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   int a[2]{ 2, 1 };
           ^
$SRC/libstdc++-v3/testsuite/25_algorithms/sort/78991.cc:39:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   std::sort(a, a+2, function{});
                             ^

FAIL: 25_algorithms/sort/78991.cc (test for excess errors)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]