Created attachment 14586 [details] Patch Current (svn rev. 242129) llvm-nm fails to build with gcc 5.1's STL -- looks like gcc 5.1's std::sort is too picky about its arguments: cd /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/tools/llvm-nm && /usr/bin/clang++ -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Oz -gdwarf-4 -Wstrict-aliasing=2 -pipe -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fPIC -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++1y -ffunction-sections -fdata-sections -Oz -gdwarf-4 -Wstrict-aliasing=2 -pipe -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fPIC -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/tools/llvm-nm -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/include -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include -o CMakeFiles/llvm-nm.dir/llvm-nm.cpp.o -c /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp:19: In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/IR/Function.h:23: In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/IR/Argument.h:17: In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/ADT/Twine.h:13: In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/ADT/SmallVector.h:22: In file included from /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/algorithm:61: In file included from /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/stl_algobase.h:71: /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/predefined_ops.h:123:31: error: indirection requires pointer operand ('(anonymous namespace)::NMSymbol' invalid) { return bool(_M_comp(*__it1, *__it2)); } ^~~~~~ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:1981:27: note: in instantiation of function template specialization '__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >::operator()<(anonymous namespace)::NMSymbol, (anonymous namespace)::NMSymbol>' requested here using _Invoke = decltype(__callable_functor(std::declval<_Functor&>()) ^ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:1990:2: note: in instantiation of template type alias '_Invoke' requested here using _Callable ^ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:2057:30: note: in instantiation of template type alias '_Callable' requested here typename = _Requires<_Callable<_Functor>, void>> ^ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:2058:2: note: in instantiation of default argument for 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> > >' required here function(_Functor); ^~~~~~~~ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/predefined_ops.h:130:14: note: while substituting deduced template arguments into function template 'function' [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >, $1 = (no value)] { return _Iter_comp_iter<_Compare>(__comp); } ^ /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/stl_algo.h:4729:54: note: in instantiation of function template specialization '__gnu_cxx::__ops::__iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >' requested here std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp)); ^ /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp:499:10: note: in instantiation of function template specialization 'std::sort<__gnu_cxx::__normal_iterator<(anonymous namespace)::NMSymbol *, std::vector<(anonymous namespace)::NMSymbol, std::allocator<(anonymous namespace)::NMSymbol> > >, std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >' requested here std::sort(SymbolList.begin(), SymbolList.end(), Cmp); ^ 1 error generated. tools/llvm-nm/CMakeFiles/llvm-nm.dir/build.make:65: recipe for target 'tools/llvm-nm/CMakeFiles/llvm-nm.dir/llvm-nm.cpp.o' failed The patch I'm attaching solves the problem for me, at the cost of making the code somewhat ugly.
Please send patches to llvm-commit.
The same error related to combining std::sort and std::function hits when compiling LibreOffice with -std=c++14 against GCC 5.1 libstdc++. It is unclear to me whether this is an issue with Clang or with libstdc++. I was able to essentially reduce the issue to the following reproducer (where I hope it really still captures the same problem as the original code), reproducible with all versions of Clang from current trunk all the way back to at least Clang 3.2: > $ cat test.cc > template<typename T> T v(); > struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); }; > template<typename F> struct Inst { > F fn; > Inst(F); > template<typename T> constexpr int operator ()(T x) const { return fn(*x); } > }; > Inst<Func> f(Func fn) { return Inst<Func>(fn); } > > $ clang++ -fsyntax-only -std=c++11 test.cc > test.cc:6:75: error: indirection requires pointer operand ('int' invalid) > template<typename T> constexpr int operator ()(T x) const { return fn(*x); } > ^~ > test.cc:2:56: note: in instantiation of function template specialization 'Inst<Func>::operator()<int>' requested here > struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); }; > ^ > test.cc:2:68: note: in instantiation of default argument for 'Func<Inst<Func> >' required here > struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); }; > ^~~~~~~ > test.cc:8:32: note: while substituting deduced template arguments into function template 'Func' > [with T = Inst<Func>, $1 = (no value)] > Inst<Func> f(Func fn) { return Inst<Func>(fn); } > ^ > 1 error generated. It is unclear to me why Clang would want to instantiate Func<Inst<Func>> at all. The problem goes away when removing the "constexpr" in line 6 (which appears to be the reason why the original problem only occurs with -std=c++14, as the corresponding "constexpr" in the original libstdc++ code is conditionally enabled only for -std=c++14).
Jordan Rupprecht pointed me at this bug, looks like I fixed it in https://reviews.llvm.org/D66310