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

Bug 328528

Summary: Wrong write access for arguments of constructor and array initializers.
Product: [Tools] CDT Reporter: Andrey Eremchenko <kamre>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle, paedu.hofer, yevshif
Version: 8.0   
Target Milestone: 8.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
patch
none
Unfinished patch none

Description Andrey Eremchenko CLA 2010-10-23 09:10:39 EDT
Build Identifier: 8.0

Sample code:

class A {
public:
	A(int p) {}
};

int main(int argc, char **argv) {
	int p = 0;
	A a(p); // here p is marked with write access
	return 0;
}


Reproducible: Always
Comment 1 Andrey Eremchenko CLA 2010-10-26 08:58:16 EDT
One more simple case with wrong write access:

void f()
{
  int i;
  int a[2] = { 0, i }; // here i is marked with write access
}
Comment 2 Patrick Hofer CLA 2010-11-03 02:53:29 EDT
Created attachment 182271 [details]
patch

fixes both examples
Comment 3 Markus Schorn CLA 2010-11-04 12:59:38 EDT
(In reply to comment #2)
> Created an attachment (id=182271) [details]
> patch
> fixes both examples

The fix is not correct, changing the ctor to:
 A(int& p) {}
should turn this into a write access.

So far the use of an expression as an argument triggers a (potential) write access. Similar a list-initializer used for initializing a class can cause a write access to a member of the list.
Comment 4 Patrick Hofer CLA 2011-05-18 01:11:33 EDT
Markus,
could you give me some detailed hints on how to solve this in a proper way?
I'd like to have this fixed for Indigo.

Thanks, Patrick
Comment 5 Markus Schorn CLA 2011-05-18 02:46:43 EDT
(In reply to comment #4)
> Markus,
> could you give me some detailed hints on how to solve this in a proper way?
> I'd like to have this fixed for Indigo.
> Thanks, Patrick

To fix the two examples in comment 0, in the method VariableReadWriteFlags.rwAnyNode() you need to consider parents of type ICPPASTConstructorInitializer and IASTInitializerList. For the former the handling should be similar to what is done for a function call, for the latter similar to the IASTEqualsInitializer.
Comment 6 Patrick Hofer CLA 2011-05-25 03:02:54 EDT
(In reply to comment #5)
Thanks, this is helpful. I'm working on the code now.
Comment 7 Patrick Hofer CLA 2011-05-28 08:18:54 EDT
Created attachment 196828 [details]
Unfinished patch

Markus, can you review this?
I'm not certain that I have understood how to solve this bug properly. There are TODO/FIXME tags in the patch which indicate where I could use some help.
Do we need to introduce ICPPASTCtorCallExpression and CPPASTCtorCallExpression? That would be unfortunate since API freeze for Indigo is over.
Comment 8 Markus Schorn CLA 2011-05-30 03:30:08 EDT
(In reply to comment #7)
> Created attachment 196828 [details]
> Unfinished patch
> Markus, can you review this?
> I'm not certain that I have understood how to solve this bug properly. There
> are TODO/FIXME tags in the patch which indicate where I could use some help.
> Do we need to introduce ICPPASTCtorCallExpression and CPPASTCtorCallExpression?
> That would be unfortunate since API freeze for Indigo is over.
I am sure we don't have to introduce new API. I'll have a look at your work, however it is too late for 8.0 anyways.
Comment 9 Markus Schorn CLA 2011-07-01 05:16:27 EDT
I did not use the patch. 
Added testcases to IndexNamesTests, fixed in 8.0.1 and 8.1.