1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 512201 - NPE in Organize Includes

Change-Id: I09d7b250697ae3ff00a5f615000512524c74ff01
This commit is contained in:
Sergey Prigogin 2017-02-14 15:55:48 -08:00
parent 78c9a0bb5e
commit 56e6da621e

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
@ -46,13 +47,13 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements ICPPSpeci
super(linkage, parent, spec.getNameCharArray()); super(linkage, parent, spec.getNameCharArray());
getDB().putRecPtr(record + SPECIALIZED, specialized.getRecord()); getDB().putRecPtr(record + SPECIALIZED, specialized.getRecord());
// Specializations that are not instances have the same map as their owner. // Specializations that are not instances have the same map as their owner except for friend functions
if (this instanceof ICPPTemplateInstance) { // declared inside a class template that are not owned by the template, but have their own template
// Defer storing of template parameter map to the post-process // parameter maps.
// to avoid infinite recursion when the evaluation of a non-type if (this instanceof ICPPTemplateInstance || !(parent instanceof ICPPSpecialization)) {
// template argument tries to store its template definition. // Defer storing of template parameter map to the post-process to avoid infinite recursion
// Until the post-process runs, temporarily store the input (possibly // when the evaluation of a non-type template argument tries to store its template definition.
// non-PDOM) map. // Until the post-process runs, temporarily store the input (possibly non-PDOM) map.
fArgMap = spec.getTemplateParameterMap(); fArgMap = spec.getTemplateParameterMap();
linkage.new ConfigureInstance(this); linkage.new ConfigureInstance(this);
} }
@ -91,14 +92,20 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements ICPPSpeci
if (this instanceof ICPPTemplateInstance) { if (this instanceof ICPPTemplateInstance) {
fArgMap= PDOMCPPTemplateParameterMap.getMap(this, getDB().getRecPtr(record + ARGMAP)); fArgMap= PDOMCPPTemplateParameterMap.getMap(this, getDB().getRecPtr(record + ARGMAP));
} else { } else {
// specializations that are no instances have the same argmap as their owner. // Specializations that are not instances have the same template parameter map as their
// owner.
IBinding owner= getOwner(); IBinding owner= getOwner();
if (owner instanceof ICPPSpecialization) { if (owner instanceof ICPPSpecialization) {
fArgMap= ((ICPPSpecialization) owner).getTemplateParameterMap(); fArgMap= ((ICPPSpecialization) owner).getTemplateParameterMap();
} else {
// Friend functions declared inside a class template are not owned by the template,
// but have their own template parameter maps.
fArgMap= PDOMCPPTemplateParameterMap.getMap(this, getDB().getRecPtr(record + ARGMAP));
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return CPPTemplateParameterMap.EMPTY;
} }
} }
return fArgMap; return fArgMap;
@ -106,14 +113,12 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements ICPPSpeci
public void storeTemplateParameterMap() { public void storeTemplateParameterMap() {
try { try {
// fArgMap here is the temporarily stored, possibly non-PDOM // fArgMap here is the temporarily stored, possibly non-PDOM map stored by the constructor.
// map stored by the constructor. Construct the PDOM map and // Construct the PDOM map and store it.
// store it.
long rec= PDOMCPPTemplateParameterMap.putMap(this, fArgMap); long rec= PDOMCPPTemplateParameterMap.putMap(this, fArgMap);
getDB().putRecPtr(record + ARGMAP, rec); getDB().putRecPtr(record + ARGMAP, rec);
// Read the stored map next time getTemplateParameterMap() // Read the stored map next time getTemplateParameterMap() is called.
// is called.
fArgMap = null; fArgMap = null;
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);