Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368419 - False positive warnings about members not initialized in constructor
Summary: False positive warnings about members not initialized in constructor
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Marc-André Laperle CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-12 03:47 EST by Axel Mueller CLA
Modified: 2012-03-19 17:02 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Mueller CLA 2012-01-12 03:47:12 EST
Build Identifier: CDT 8.1

I get false positive warnings about members not initialized in constructor when constructor calls non-const method.

see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339795#c51

Current implementation of checker only works when constructor definition is in header file but fails if definition is in .cpp source file.





Reproducible: Always
Comment 1 Marc-André Laperle CLA 2012-02-27 12:55:58 EST
Hi Axel, I tried this and couldn't reproduce the false positive:

---test.h---

#ifndef TEST_H_
#define TEST_H_

 class C {
 public:
     int field;
     C();
};

#endif

---test.cpp---

#include "test.h"

void initObject(C* c);

C::C() {
	initObject(this);
}

Does that work for you?
Comment 2 Marc-André Laperle CLA 2012-02-27 12:58:07 EST
(In reply to comment #1)
> Hi Axel, I tried this and couldn't reproduce the false positive:

That was using master b939129f (8.1) which is about a week old.
Comment 3 Marc-André Laperle CLA 2012-02-27 13:41:56 EST
Ah I see now a fp now if I put initObject inside the class to make it a method. Was that the fp you encountered?
Comment 4 Axel Mueller CLA 2012-02-28 03:34:55 EST
> Ah I see now a fp now if I put initObject inside the class to make it a method.
> Was that the fp you encountered?
I was using the code you mentioned in comment #1. I used a nightly build from January to test it. You might have found another fp.
Comment 5 CDT Genie CLA 2012-03-07 02:23:01 EST
*** cdt git genie on behalf of Marc-Andre Laperle ***

    Bug 368419 - FP in members not initialized in constructor

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=0a9a95adcd3ba273c1b67a11483d19d435f2b2f2
Comment 6 Marc-André Laperle CLA 2012-03-18 14:44:28 EDT
(In reply to comment #4)
> > Ah I see now a fp now if I put initObject inside the class to make it a method.
> > Was that the fp you encountered?
> I was using the code you mentioned in comment #1. I used a nightly build from
> January to test it. You might have found another fp.

I fixed the fp when the non-const method is used but I still can't reproduce the fp when a function is used. Sorry to ask but can you try again with a recent nightly build? I must be missing something... or maybe you really did have initObject as a method.
Comment 7 Axel Mueller CLA 2012-03-19 16:58:09 EDT
(In reply to comment #6)
> I fixed the fp when the non-const method is used but I still can't reproduce
> the fp when a function is used. Sorry to ask but can you try again with a
> recent nightly build? I must be missing something... or maybe you really did
> have initObject as a method.
I think you are right. I had initObject() as a method. That is the usual way I implement a class. So I can reset the object anytime I want by calling initObject(). You can close the bug then.
Comment 8 Marc-André Laperle CLA 2012-03-19 17:02:13 EDT
OK, thanks Axel!