Martin Perry
Martin Perry

Reputation: 9527

Visual Studio 2013 - std::enable_if warning 4544

I have written this code

In class in header

template <typename T,
typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
T GetResultValueAsNumber(char * result);

than in inline file

 template <
        typename T,
        typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type
    >
    T PostgreSQLWrapper::GetResultValueAsNumber(char * result)
    {    
        double value = strtod(result, NULL);

        return static_cast<T>(value);
    };

In Visual Studio 2013 I got this warning (but code works correctly)

warning C4544: '<unnamed-symbol>' : default template argument ignored on this template declaration - see declaration of '<unnamed-symbol>'

What does it mean?

Upvotes: 4

Views: 905

Answers (2)

Columbo
Columbo

Reputation: 60979

VC++ isn't conforming here; The program is ill-formed. GCC and Clang refuse to compile similar code.

§14.1/10:

The set of default template-arguments available for use is obtained by merging the default arguments from all prior declarations of the template in the same way default function arguments are (8.3.6).

§8.3.6/4:

A default argument shall not be redefined by a later declaration (not even to the same value).

/6 shows an example as well:

Except for member functions of class templates, the default arguments in a member function definition that appears outside of the class definition are added to the set of default arguments provided by the member function declaration in the class definition; […] [ Example:

class C {
    void f(int i = 3);
};

void C::f(int i = 3) {   // error: default argument already
}                        // specified in class scope

// […]

end example ]

Upvotes: 4

Bo Persson
Bo Persson

Reputation: 92241

A default value can only be given once, so if it is in the header it cannot be restated with the definition of the function. Just remove (or comment out) the default.

Upvotes: 2

Related Questions