Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323278

Summary: Indexer reports "return has value, in function returning void" when void func returns the return value of void func.
Product: [Tools] CDT Reporter: Tim Black <timblaktu>
Component: cdt-codanAssignee: Project Inbox <cdt-core-inbox>
Status: RESOLVED WORKSFORME QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Tim Black CLA 2010-08-20 14:10:01 EDT
Build Identifier: 20100617-1415

I have some void functions that return the value from other void functions, and the indexer erroneously reports "return has value, in function returning void" in some cases. The compiler of course is fine with this, so when I compile, the Problem window clears. But when the indexer runs again, they come back. This problem seems to happen only when the inner void function is defined in another file.

On the cdt-dev list, kesselhaus added: 
Even though the code was C++, but in C the failure is actually correct:
"A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void."


Reproducible: Always

Steps to Reproduce:
1. add defs (see below) to a .h file and let the indexer run.
2. wait for "return has value, in function returning void" to appear in problems view.

These defs in a .h cause the error:

#include <vector>
using std::vector;
    template <class T>
    class MyVector {
      private:
        vector<int> m_v;
      public:
        MyVector() : m_v() {}
        void push_back(T t) { return m_v.push_back(t); }  // "Return has value, in function returning void"
    };

But this in a .h does not:

    template <class T>
    class MyClass {
        void foo() { return goo(); }
        void goo() {}
    };

And this in a .cpp does not:

void goo() { }
void foo() {
  return goo();
}
Comment 1 Elena Laskavaia CLA 2011-05-01 22:06:58 EDT
I copy example to my project - I cannot reproduce it.
If I comment out include <vector> I can reproduce - but it is correct
behavior if it is unknown function used in return statement we assume
it does report value. Make sure your indexer is set up properly to resolve
include. If it is still reproducible try to run it on preprocessed code
and attach it here.