Fix compilation issues with C++17

Testable on Linux/macOS by changing c++14 to c++1z in qtcreator.pri.
Testable with latest MSVC2017 by setting _CL_=/std:c++17.

unary_function, binary_function, and a few other things that were
deprecated are removed in C++17.
std::string got a non-const overload for its "data" member function,
so we cannot create a function pointer on it without specifying its
type. Use std::declval instead (though it requires a default constructor
for the type).

MSVC seems to have an issue with Utils::transform for std::vector
(used in Nim plugin), but that looks like a compiler issue.

Change-Id: I94f9a93d591d55b610f86fabfc618158927d6221
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2018-05-31 11:31:59 +02:00
parent 8798990fb1
commit f8e88e8ce4
12 changed files with 42 additions and 19 deletions

View File

@@ -465,7 +465,7 @@ inline V search_map(const std::map<K, V>& mapping,
* Function adaptor for delete operation * Function adaptor for delete operation
*/ */
template<class T> template<class T>
class del_fun : public std::unary_function<T, void> class del_fun
{ {
public: public:
void operator()(T* ptr) { delete ptr; } void operator()(T* ptr) { delete ptr; }

View File

@@ -59,7 +59,7 @@ public:
bool match(const Name *other, Matcher *matcher = 0) const; bool match(const Name *other, Matcher *matcher = 0) const;
public: public:
struct Compare: std::binary_function<const Name *, const Name *, bool> { struct Compare {
bool operator()(const Name *name, const Name *other) const; bool operator()(const Name *name, const Name *other) const;
}; };

View File

@@ -101,7 +101,7 @@ public:
bool isSpecialization() const { return _isSpecialization; } bool isSpecialization() const { return _isSpecialization; }
// Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::map) // Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::map)
struct Compare: std::binary_function<const TemplateNameId *, const TemplateNameId *, bool> { struct Compare {
bool operator()(const TemplateNameId *name, const TemplateNameId *other) const; bool operator()(const TemplateNameId *name, const TemplateNameId *other) const;
}; };

View File

@@ -71,7 +71,7 @@ template <typename Type>
class TypeTable class TypeTable
{ {
public: public:
struct Compare: std::binary_function<Type, Type, bool> { struct Compare {
bool operator()(const Type &value, const Type &other) const { bool operator()(const Type &value, const Type &other) const {
return value.isLessThan(&other); return value.isLessThan(&other);
} }

View File

@@ -245,7 +245,7 @@ AbstractSymbolGroupNodePtrVector linkedListChildList(SymbolGroupValue headNode,
} }
// Helper function for linkedListChildList that returns a member by name // Helper function for linkedListChildList that returns a member by name
class MemberByName : public std::unary_function<const SymbolGroupValue &, SymbolGroupValue> class MemberByName
{ {
public: public:
explicit MemberByName(const char *name) : m_name(name) {} explicit MemberByName(const char *name) : m_name(name) {}

View File

@@ -52,7 +52,7 @@ void split(const std::string &s, char sep, Iterator it)
// A boolean predicate that can be used for grepping sequences // A boolean predicate that can be used for grepping sequences
// of strings for a 'needle' substring. // of strings for a 'needle' substring.
class SubStringPredicate : public std::unary_function<const std::string &, bool> class SubStringPredicate
{ {
public: public:
explicit SubStringPredicate(const char *needle) : m_needle(needle) {} explicit SubStringPredicate(const char *needle) : m_needle(needle) {}

View File

@@ -251,7 +251,7 @@ std::string SymbolGroup::debug(const std::string &iname,
typedef std::pair<unsigned, std::string> InamePathEntry; typedef std::pair<unsigned, std::string> InamePathEntry;
struct InamePathEntryLessThan : public std::binary_function<InamePathEntry, InamePathEntry, bool> { struct InamePathEntryLessThan
bool operator()(const InamePathEntry &i1, const InamePathEntry& i2) const bool operator()(const InamePathEntry &i1, const InamePathEntry& i2) const
{ {
if (i1.first < i2.first) if (i1.first < i2.first)

View File

@@ -39,9 +39,7 @@ using enable_if_has_char_data_pointer = typename std::enable_if_t<
std::is_same< std::is_same<
std::remove_const_t< std::remove_const_t<
std::remove_pointer_t< std::remove_pointer_t<
std::result_of_t< decltype(std::declval<const String>().data())
decltype(&String::data)(String)
>
> >
>, char>::value >, char>::value
, int>; , int>;

View File

@@ -168,7 +168,7 @@ static QList<QByteArray> fullIdForSymbol(CPlusPlus::Symbol *symbol)
namespace { namespace {
class ProcessFile: public std::unary_function<QString, QList<CPlusPlus::Usage> > class ProcessFile
{ {
const WorkingCopy workingCopy; const WorkingCopy workingCopy;
const CPlusPlus::Snapshot snapshot; const CPlusPlus::Snapshot snapshot;
@@ -177,6 +177,10 @@ class ProcessFile: public std::unary_function<QString, QList<CPlusPlus::Usage> >
QFutureInterface<CPlusPlus::Usage> *future; QFutureInterface<CPlusPlus::Usage> *future;
public: public:
// needed by QtConcurrent
using argument_type = const Utils::FileName &;
using result_type = QList<CPlusPlus::Usage>;
ProcessFile(const WorkingCopy &workingCopy, ProcessFile(const WorkingCopy &workingCopy,
const CPlusPlus::Snapshot snapshot, const CPlusPlus::Snapshot snapshot,
CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Document::Ptr symbolDocument,
@@ -230,7 +234,7 @@ public:
} }
}; };
class UpdateUI: public std::binary_function<QList<CPlusPlus::Usage> &, QList<CPlusPlus::Usage>, void> class UpdateUI
{ {
QFutureInterface<CPlusPlus::Usage> *future; QFutureInterface<CPlusPlus::Usage> *future;
@@ -596,7 +600,7 @@ static void searchFinished(SearchResult *search, QFutureWatcher<CPlusPlus::Usage
namespace { namespace {
class FindMacroUsesInFile: public std::unary_function<QString, QList<CPlusPlus::Usage> > class FindMacroUsesInFile
{ {
const WorkingCopy workingCopy; const WorkingCopy workingCopy;
const CPlusPlus::Snapshot snapshot; const CPlusPlus::Snapshot snapshot;
@@ -604,6 +608,10 @@ class FindMacroUsesInFile: public std::unary_function<QString, QList<CPlusPlus::
QFutureInterface<CPlusPlus::Usage> *future; QFutureInterface<CPlusPlus::Usage> *future;
public: public:
// needed by QtConcurrent
using argument_type = const Utils::FileName &;
using result_type = QList<CPlusPlus::Usage>;
FindMacroUsesInFile(const WorkingCopy &workingCopy, FindMacroUsesInFile(const WorkingCopy &workingCopy,
const CPlusPlus::Snapshot snapshot, const CPlusPlus::Snapshot snapshot,
const CPlusPlus::Macro &macro, const CPlusPlus::Macro &macro,

View File

@@ -683,7 +683,7 @@ static QString matchingLine(unsigned position, const QString &source)
return source.mid(start, end - start); return source.mid(start, end - start);
} }
class ProcessFile: public std::unary_function<QString, QList<FindReferences::Usage> > class ProcessFile
{ {
ContextPtr context; ContextPtr context;
typedef FindReferences::Usage Usage; typedef FindReferences::Usage Usage;
@@ -692,6 +692,10 @@ class ProcessFile: public std::unary_function<QString, QList<FindReferences::Usa
QFutureInterface<Usage> *future; QFutureInterface<Usage> *future;
public: public:
// needed by QtConcurrent
using argument_type = const QString &;
using result_type = QList<Usage>;
ProcessFile(const ContextPtr &context, ProcessFile(const ContextPtr &context,
QString name, QString name,
const ObjectValue *scope, const ObjectValue *scope,
@@ -721,7 +725,7 @@ public:
} }
}; };
class SearchFileForType: public std::unary_function<QString, QList<FindReferences::Usage> > class SearchFileForType
{ {
ContextPtr context; ContextPtr context;
typedef FindReferences::Usage Usage; typedef FindReferences::Usage Usage;
@@ -730,6 +734,10 @@ class SearchFileForType: public std::unary_function<QString, QList<FindReference
QFutureInterface<Usage> *future; QFutureInterface<Usage> *future;
public: public:
// needed by QtConcurrent
using argument_type = const QString &;
using result_type = QList<Usage>;
SearchFileForType(const ContextPtr &context, SearchFileForType(const ContextPtr &context,
QString name, QString name,
const ObjectValue *scope, const ObjectValue *scope,
@@ -759,12 +767,17 @@ public:
} }
}; };
class UpdateUI: public std::binary_function<QList<FindReferences::Usage> &, QList<FindReferences::Usage>, void> class UpdateUI
{ {
typedef FindReferences::Usage Usage; typedef FindReferences::Usage Usage;
QFutureInterface<Usage> *future; QFutureInterface<Usage> *future;
public: public:
// needed by QtConcurrent
using first_argument_type = QList<Usage> &;
using second_argument_type = const QList<Usage> &;
using result_type = void;
UpdateUI(QFutureInterface<Usage> *future): future(future) {} UpdateUI(QFutureInterface<Usage> *future): future(future) {}
void operator()(QList<Usage> &, const QList<Usage> &usages) void operator()(QList<Usage> &, const QList<Usage> &usages)

View File

@@ -59,7 +59,7 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
QList<int> mibs = QTextCodec::availableMibs(); QList<int> mibs = QTextCodec::availableMibs();
Utils::sort(mibs); Utils::sort(mibs);
QList<int>::iterator firstNonNegative = QList<int>::iterator firstNonNegative =
std::find_if(mibs.begin(), mibs.end(), std::bind2nd(std::greater_equal<int>(), 0)); std::find_if(mibs.begin(), mibs.end(), [](int n) { return n >=0; });
if (firstNonNegative != mibs.end()) if (firstNonNegative != mibs.end())
std::rotate(mibs.begin(), firstNonNegative, mibs.end()); std::rotate(mibs.begin(), firstNonNegative, mibs.end());
foreach (int mib, mibs) { foreach (int mib, mibs) {

View File

@@ -144,7 +144,9 @@ bool Rule::charPredicateMatchSucceed(const QString &text,
ProgressData *progress, ProgressData *progress,
bool (QChar::* predicate)() const) const bool (QChar::* predicate)() const) const
{ {
return predicateMatchSucceed(text, length, progress, std::mem_fun_ref(predicate)); return predicateMatchSucceed(text, length, progress, [predicate](const QChar &c) {
return (c.*predicate)();
});
} }
bool Rule::charPredicateMatchSucceed(const QString &text, bool Rule::charPredicateMatchSucceed(const QString &text,
@@ -152,7 +154,9 @@ bool Rule::charPredicateMatchSucceed(const QString &text,
ProgressData *progress, ProgressData *progress,
bool (*predicate)(const QChar &)) const bool (*predicate)(const QChar &)) const
{ {
return predicateMatchSucceed(text, length, progress, std::ptr_fun(predicate)); return predicateMatchSucceed(text, length, progress, [predicate](const QChar &c) {
return predicate(c);
});
} }
bool Rule::matchSucceed(const QString &text, const int length, ProgressData *progress) bool Rule::matchSucceed(const QString &text, const int length, ProgressData *progress)