Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns incorrect result for method call
Summary: CPPVariableReadWriteFlags.getReadWriteFlags returns incorrect result for meth...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Sergey Prigogin CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-07 15:58 EST by Sergey Prigogin CLA
Modified: 2012-02-29 13:24 EST (History)
2 users (show)

See Also:
eclipse.sprigogin: iplog-
mschorn.eclipse: review+


Attachments
Proposed fix (3.67 KB, patch)
2012-02-07 23:48 EST, Sergey Prigogin CLA
eclipse.sprigogin: iplog-
mschorn.eclipse: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2012-02-07 15:58:34 EST
In the following code

class A {
public:
  void m();
};

void test() {
  A a;
  a.m();
}

CPPVariableReadWriteFlags.getReadWriteFlags returns READ for 'a' in a.m(). It should return WRITE since the method m is not declared const.
Comment 1 Sergey Prigogin CLA 2012-02-07 20:59:59 EST
Created VariableReadWriteFlagsTest, which uncovered two more problems:

1.
int a = 1;  READ | WRITE instead of expected WRITE

2.
struct A { int x; };

void test() {
  A a;
  a.x = 1;  READ instead of expected WRITE
};
Comment 2 Sergey Prigogin CLA 2012-02-07 23:48:00 EST
Created attachment 210705 [details]
Proposed fix

Markus,
Could you please review the attached fix for the function call issue. Thanks.
Comment 3 Markus Schorn CLA 2012-02-08 02:57:16 EST
Comment on attachment 210705 [details]
Proposed fix

Looks good to me.
Comment 4 Markus Schorn CLA 2012-02-08 03:21:08 EST
(In reply to comment #3)
> Comment on attachment 210705 [details]
> Proposed fix
> Looks good to me.

It just came to my mind that you may have to check the indirection of using the variable. The indirection is passed around as an argument and is modified when one of the operators [], *, & is encountered. Currently it is not adjusted when the operator -> is found.

void test() {
  A* ap;
  A  a;
  (*ap).m();  // read access to ap
  ap->m();    // read access to ap
  (&a)->m();  // read/write access to a
}
Comment 5 Sergey Prigogin CLA 2012-02-08 20:31:07 EST
Fixed in master.
Comment 6 CDT Genie CLA 2012-02-29 13:24:39 EST
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37
Comment 7 CDT Genie CLA 2012-02-29 13:24:41 EST
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37