Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359376 - [Index] Implicit default constructor returned as constructor after defining an explicit constructor.
Summary: [Index] Implicit default constructor returned as constructor after defining a...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: 8.1.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-29 05:21 EDT by Thomas Corbat CLA
Modified: 2012-02-23 11:33 EST (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 Thomas Corbat CLA 2011-09-29 05:21:15 EDT
Build Identifier: I20110613-1736

When declaring a variable with a type defined in another file (included header), the default constructor is one of the constructors returned by ICPPClassType.getConstructors(), after adding an explicit constructor to that type.

Detail: I have two files
//A.cpp
#include "B.h"
void foo(){
  B b;
}

//B.h
struct B{
};

In the context of the file A.h there is an implicit name at "b" indicating the relation to the implicit default constructor in "B". This is as expected so far. If I add an explicit non-default constructor to B, this implicit name remains:
//A.cpp
#include "B.h"
void foo(){
  B b;
}

//B.h
struct B{
  B(int i){}
};

At least it remains until I rebuild the index of the project. The same behavior is observable if I query the ICPPClassType binding for the declaration specifier "B" in "A.cpp" for its constructors (by calling "getConstructors()"). The index gets updated after adding the explicit constructor to B, as it is returned by "getConstructor()" in addition to the implicit default- and copy-constructor.

I cannot observe this behavior if I define "B" in "A.cpp".

I'm not quite sure where the problem occurs or to fix it. Can the implicit default constructor binding be removed when adding an explicit constructor? 

Afaik the resolution in "ICPPClassType.getConstructors()" returns all declared and implicit constructors, perhaps it has to be filtered there. But I guess this would not solve the problem of the implicit name at "B b;" in "A.cpp".


Reproducible: Always

Steps to Reproduce:
1. Create header file with type definition.
2. Create source file declaring a variable using the type defined in the header file.
3. Add an explicit non-default constructor to the type in the header file.
4. Query the type binding in the variable declaration in the source file for its constructors.
Comment 1 Markus Schorn CLA 2011-09-30 08:14:40 EDT
Added testcase and fix:
I remove the implicit flag of the method, when updating the class.
Comment 2 CDT Genie CLA 2011-10-03 10:23:29 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 359376: Updating implicit ctors in index.

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