Bug 309611 - Implementation of methods goes to wrong file, if that wrong file contains a friend function
Summary: Implementation of methods goes to wrong file, if that wrong file contains a f...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 6.0.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-18 18:35 EDT by Jost CLA
Modified: 2020-09-04 15:19 EDT (History)
1 user (show)

See Also:


Attachments
Header for the class (229 bytes, application/octet-stream)
2010-04-18 18:36 EDT, Jost CLA
no flags Details
Implementation for the class (40 bytes, application/octet-stream)
2010-04-18 18:37 EDT, Jost CLA
no flags Details
Independent file (216 bytes, application/octet-stream)
2010-04-18 18:37 EDT, Jost CLA
no flags Details
Minimal project to verify the problem (2.34 KB, application/x-zip-compressed)
2013-04-23 14:33 EDT, Jesse Weinstein CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jost CLA 2010-04-18 18:35:00 EDT
Build Identifier: 201002161416

Consider a class having a friend function which is implemented in an independent file (i.e. it is not implemented in the header or .cpp file for that class). If you create a new method declaration in the header of the class, and then select "Source->Implement Method..." for that method, the refactoring programm creates the method stub in the same file containing the friend functions definition.

I can't point to the exact circumstances to reproduce the bug, but the example below should hopefully be a good starting point.

Reproducible: Sometimes

Steps to Reproduce:
1. Create a new empty C++ executable project.
2. Add the three appended files to the project (all to the root directory).
3. Build the project.
4. Add a method declaration void FooBar() to the definition of class CFoo.
5. Select "Source->Implement Method..." for that method and let the refactoring engine implement the stub.
6. The generated method stub can be found in the file Printers.h, which should be considered an error.
Comment 1 Jost CLA 2010-04-18 18:36:34 EDT
Created attachment 165217 [details]
Header for the class
Comment 2 Jost CLA 2010-04-18 18:37:01 EDT
Created attachment 165218 [details]
Implementation for the class
Comment 3 Jost CLA 2010-04-18 18:37:19 EDT
Created attachment 165219 [details]
Independent file
Comment 4 Jesse Weinstein CLA 2013-04-23 14:33:46 EDT
Created attachment 230046 [details]
Minimal project to verify the problem

Verified on eclipse-SDK-4.3M5a-win32-x86_64. Here's a minimal project, simplified from the example provided by the reporter (there's no need for including iostreams, etc.). 

This could be considered an enhancement, rather than a bug, as the code generated is not *wrong*, merely not what the reporter expected. Nevertheless, it would be good to look into how Implement Method decides where to put code, and possibly add some configuration options.