Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333255 - Parser gives bogus warning about no return value when SFINAE is used
Summary: Parser gives bogus warning about no return value when SFINAE is used
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0   Edit
Assignee: Elena Laskavaia CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-27 23:07 EST by Nathan Ridge CLA
Modified: 2012-07-02 22:02 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Ridge CLA 2010-12-27 23:07:19 EST
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.
Comment 1 Elena Laskavaia CLA 2011-02-23 22:03:58 EST
best approach not deal with templates they too complex to analyse
-> fixed
Comment 2 CDT Genie CLA 2011-02-23 22:23:26 EST
*** 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
Comment 3 Nathan Ridge CLA 2012-07-02 21:21:00 EDT
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
    {
    }
};
Comment 4 Nathan Ridge CLA 2012-07-02 21:21:34 EDT
a bogus warning i mean
Comment 5 Nathan Ridge CLA 2012-07-02 22:02:49 EDT
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.