| Summary: | Parser gives bogus warning about no return value when SFINAE is used | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Nathan Ridge <zeratul976> |
| Component: | cdt-codan | Assignee: | Elena Laskavaia <elaskavaia.cdt> |
| Status: | RESOLVED FIXED | QA Contact: | Elena Laskavaia <elaskavaia.cdt> |
| Severity: | normal | ||
| Priority: | P3 | CC: | cdtdoug |
| Version: | 8.0 | ||
| Target Milestone: | 8.0 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
best approach not deal with templates they too complex to analyse -> fixed *** cdt cvs genie on behalf of elaskavaia *** Bug 333255 - Parser gives bogus warning about no return value when SFINAE is used [*] ReturnChecker.java 1.18 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java?root=Tools_Project&r1=1.17&r2=1.18 Eclipse still gives a bodu warning if the function itself is not a template but it's in a template class:
template <bool Cond, typename T = void>
struct enable_if
{
typedef T type;
};
template <typename T>
struct enable_if<false, T> {};
template <typename T>
struct is_int
{
static const bool value = false;
};
template <>
struct is_int<int>
{
static const bool value = true;
};
template <typename T>
struct S
{
typename enable_if<is_int<T>::value, void>::type f(T) // WARNING HERE
{
}
};
a bogus warning i mean Never mind, that second example is invalid (you cannot selectively disable a member function of a template class with enable_if unless that member function is also a template and the condition of the enable_if depends on the template parameters of the member function, not just those of the class). Sorry for the noise. |
For the following code: template <bool Cond, typename T = void> struct enable_if { typedef T type; }; template <typename T> struct enable_if<false, T> {}; template <typename T> struct is_int { static const bool value = false; }; template <> struct is_int<int> { static const bool value = true; }; template <typename T> typename enable_if<is_int<T>::value, void>::type f(T) // WARNING HERE { } The parser gives a warning "No return, in function returning non-void" at the definition of f. This is a bogus warning. The code uses SFINAE to ensure that this version of f is only considered in an overload resolution set if the condition is_int<T>::value is true, and in this case, the return value *is* void.