Bug 393038

Summary: False positive check "function-args-by-value". Template override case.
Product: [Developer tools] clazy Reporter: Roman <dismine>
Component: generalAssignee: Sergio Martins <smartins>
Status: ASSIGNED ---    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Roman 2018-04-12 10:59:19 UTC
Hi,

Maybe this is duplicate for issue https://bugs.kde.org/show_bug.cgi?id=391812, but because i cannot check i create new issue.

In my project i have this code:
class MyClass
{
public:
    template <typename T>
    void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
};

template <typename T>
inline void MyClass::SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
{
    // See specification for xs:decimal
    const QLocale locale = QLocale::c();
    domElement.setAttribute(name, locale.toString(value).remove(locale.groupSeparator()));
}

template <>
inline void MyClass::SetAttribute<QString>(QDomElement &domElement, const QString &name, const QString &value) const
{
    domElement.setAttribute(name, value);
}

template <>
inline void MyClass::SetAttribute<QChar>(QDomElement &domElement, const QString &name, const QChar &value) const
{
    domElement.setAttribute(name, value);
}

template <>
inline void MyClass::SetAttribute<bool>(QDomElement &domElement, const QString &name, const bool &value) const
{
    domElement.setAttribute(name, value ? QStringLiteral("true") : QStringLiteral("false"));
}

Clazy correctly warns about bool and QChar arguments, but i cannot change the function declaration, it won't compile with error "no function template matches function template specialization 'SetAttribute'".