Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348387 - Wrong warning "No return, in function returning non-void"
Summary: Wrong warning "No return, in function returning non-void"
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.1.2   Edit
Assignee: Marc-André Laperle CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
: 355938 368261 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-06-06 08:40 EDT by Jens Seidel CLA
Modified: 2014-01-29 22:53 EST (History)
9 users (show)

See Also:


Attachments
Fix and tests (10.12 KB, patch)
2011-07-28 12:28 EDT, Tomasz Wesolowski CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Seidel CLA 2011-06-06 08:40:24 EDT
Build Identifier: 20110526-1053

I get on the following code the wrong warning
"No return, in function returning non-void"

Reproducible: Always

Steps to Reproduce:
int main()
{
	try {
		return 3;
	}
	catch (...) {
		return 2;
	}
}
Comment 1 Tomasz Wesolowski CLA 2011-07-28 12:28:42 EDT
Created attachment 200544 [details]
Fix and tests

2 distinct issues were here:
- CFG didn't handle catch(...) correctly,
- the checker didn't consider the try block statement  a compound statement (the same goes for range based for statement from c++0x, also fixed)

BTW:
The patch fixes the checker but the CFG View can't display the graph for the code from summary. However, it displays correct CFG when you wrap all the function body in a `if (1)` condition or something.
Alena, could you have a look on this?
Comment 2 Matt Hargett CLA 2011-12-20 14:20:35 EST
I have this issue in both CDT 8.0 and current trunk (Build id: 20111215-0110). Getting this fix applied for M5 or M6 would be great. Let me know if any testing would help.

It's great that many of the issues I'm having already have fixes in progress :)
Comment 3 Francisco Mising name CLA 2012-06-29 07:49:16 EDT
The following code also triggers the warning:

int test2_f();
int test1_f() {
	while (1) {
		if (test2_f()) {
			return 1;
		}
	}
}

This is in the juno release.
Comment 4 Rob Riggs CLA 2012-11-12 10:29:17 EST
I have the same problem with this on Juno/CDT 8.1.1:

int foo()
{
    try
    {
        return 1;
    }
    catch (std::runtime_error& ex)
    {
         throw;
    }
}

Is this case addressed by the submitted patch?

When do we think the fix will be merged?  The bug still shows as NEW 16 months after reported and fixed?
Comment 5 Marc-André Laperle CLA 2012-11-15 23:51:20 EST
*** Bug 355938 has been marked as a duplicate of this bug. ***
Comment 6 Marc-André Laperle CLA 2012-11-16 23:43:55 EST
(In reply to comment #1)
> BTW:
> The patch fixes the checker but the CFG View can't display the graph for the
> code from summary. However, it displays correct CFG when you wrap all the
> function body in a `if (1)` condition or something.
> Alena, could you have a look on this?

This doesn't seem related to the fix since this sample code also has the same problem:

int foo(int a) {
    if(a)
    {
        return 1;
    }
    else
    {
        return 1;
    }
}

ViewContentProvider.getFlat calls getMergeNode().getOutgoing() which returns null.
Comment 7 Marc-André Laperle CLA 2012-11-17 01:58:48 EST
Patch applied to 8_1 and master with minor modifications. Thank you!

http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=660a75531a7fab3095eabb2fc8e0de5250a30916
Comment 8 Nathan Ridge CLA 2012-11-17 17:31:15 EST
The test case in comment 3 is a different issue. I filed it at https://bugs.eclipse.org/bugs/show_bug.cgi?id=394521.
Comment 9 Marc-André Laperle CLA 2012-11-17 20:06:50 EST
(In reply to comment #4)
> Is this case addressed by the submitted patch?

Yes.
Comment 10 CDT Genie CLA 2013-02-27 11:55:57 EST
*** cdt git genie on behalf of Tomasz Wesolowski ***

    Bug 348387 - fp in ReturnChecker using try/catch

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=660a75531a7fab3095eabb2fc8e0de5250a30916
Comment 11 CDT Genie CLA 2013-02-27 11:56:00 EST
*** cdt git genie on behalf of Tomasz Wesolowski ***

    Bug 348387 - fp in ReturnChecker using try/catch

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=5e369d662ebc55256faf14dc8b0998a898d4e85f
Comment 12 Marc-André Laperle CLA 2013-07-18 00:01:32 EDT
*** Bug 368261 has been marked as a duplicate of this bug. ***