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

Added failing IndexCPPTemplateResolutionTest._testSFINAE_a test.

This commit is contained in:
Sergey Prigogin 2012-08-12 17:25:57 -07:00
parent c479c6ccb7
commit aaa0f85bb3
3 changed files with 180 additions and 64 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2010 Symbian Software Systems and others. * Copyright (c) 2006, 2012 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -20,6 +20,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@ -59,30 +60,30 @@ import org.osgi.framework.Bundle;
* is backed by the PDOM), it must be possible to resolve which binding a name * is backed by the PDOM), it must be possible to resolve which binding a name
* in the AST is referring to. If the binding is not defined in the AST fragment * in the AST is referring to. If the binding is not defined in the AST fragment
* then it is assumed to have come from a file which is already indexed. * then it is assumed to have come from a file which is already indexed.
* *
* This class is for testing the process by which bindings are looked up in * This class is for testing the process by which bindings are looked up in
* the PDOM purely from AST information (i.e. without a real binding from the DOM) * the PDOM purely from AST information (i.e. without a real binding from the DOM)
*/ */
public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
private static final boolean DEBUG= false; private static final boolean DEBUG= false;
protected ITestStrategy strategy; protected ITestStrategy strategy;
public void setStrategy(ITestStrategy strategy) { public void setStrategy(ITestStrategy strategy) {
this.strategy = strategy; this.strategy = strategy;
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
strategy.setUp(); strategy.setUp();
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
strategy.tearDown(); strategy.tearDown();
super.tearDown(); super.tearDown();
} }
protected IASTName findName(String section, int len) { protected IASTName findName(String section, int len) {
if (len == 0) if (len == 0)
len= section.length(); len= section.length();
@ -97,10 +98,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return name; return name;
} }
} }
return null; return null;
} }
/** /**
* Attempts to get an IBinding from the initial specified number of characters * Attempts to get an IBinding from the initial specified number of characters
* from the specified code fragment. Fails the test if * from the specified code fragment. Fails the test if
@ -122,25 +123,25 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IASTName name= findName(section, len); IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name); assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature()); assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding); assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
assertInstance(binding, clazz, cs); assertInstance(binding, clazz, cs);
return clazz.cast(binding); return clazz.cast(binding);
} }
/* /*
* @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int) * @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int)
*/ */
protected <T extends IBinding> T getBindingFromASTName(String section, int len) { protected <T extends IBinding> T getBindingFromASTName(String section, int len) {
if (len <= 0) if (len <= 0)
len += section.length(); len += section.length();
IASTName name= findName(section, len); IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name); assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature()); assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding); assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
@ -157,17 +158,17 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IASTName name= findName(section, len); IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name); assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature()); assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding); assertNotNull("No binding for " + name.getRawSignature(), binding);
assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
return name.resolveBinding(); return name.resolveBinding();
} }
protected static void assertQNEquals(String expectedQN, IBinding b) { protected static void assertQNEquals(String expectedQN, IBinding b) {
assertInstance(b, IBinding.class); assertInstance(b, IBinding.class);
if (b instanceof ICPPBinding) { if (b instanceof ICPPBinding) {
assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding)b)); assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding) b));
} else { } else {
assertEquals(expectedQN, b.getName()); assertEquals(expectedQN, b.getName());
} }
@ -175,7 +176,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
protected IType getVariableType(IBinding binding) throws DOMException { protected IType getVariableType(IBinding binding) throws DOMException {
assertTrue(binding instanceof IVariable); assertTrue(binding instanceof IVariable);
return ((IVariable)binding).getType(); return ((IVariable) binding).getType();
} }
protected IType getPtrType(IBinding binding) throws DOMException { protected IType getPtrType(IBinding binding) throws DOMException {
@ -195,8 +196,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
// assert function is IFunctionType // assert function is IFunctionType
IFunctionType ft = (IFunctionType) function; IFunctionType ft = (IFunctionType) function;
assertTrue(ICPPClassType.class.isInstance((ft.getParameterTypes()[index]))); assertTrue(ICPPClassType.class.isInstance((ft.getParameterTypes()[index])));
assertEquals(compositeTypeKey, ((ICPPClassType)ft.getParameterTypes()[index]).getKey()); assertEquals(compositeTypeKey, ((ICPPClassType) ft.getParameterTypes()[index]).getKey());
assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType)ft.getParameterTypes()[index])); assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType) ft.getParameterTypes()[index]));
} }
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) { protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
@ -207,7 +208,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
} }
return clazz.cast(o); return clazz.cast(o);
} }
protected String readTaggedComment(final String tag) throws IOException { protected String readTaggedComment(final String tag) throws IOException {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag); return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag);
} }
@ -216,6 +217,63 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return strategy.getIndex(); return strategy.getIndex();
} }
protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) {
assertInstance(b, IVariable.class);
IVariable variable = (IVariable) b;
assertQNEquals(qn, variable);
assertInstance(variable.getType(), expType);
if (expTypeQN != null) {
IType type= variable.getType();
assertInstance(type, IBinding.class);
assertQNEquals(expTypeQN, (IBinding) type);
}
}
protected static void assertTypeContainer(IType conType, String expQN, Class containerType, Class expContainedType, String expContainedTypeQN) {
assertInstance(conType, ITypeContainer.class);
assertInstance(conType, containerType);
IType containedType= ((ITypeContainer) conType).getType();
assertInstance(containedType, expContainedType);
if (expContainedTypeQN != null) {
assertInstance(containedType, IBinding.class);
assertQNEquals(expContainedTypeQN, (IBinding) containedType);
}
}
final protected void checkBindings() throws Exception {
for (int i = 0; i < strategy.getAstCount(); i++) {
IASTTranslationUnit ast = strategy.getAst(i);
CNameCollector col = new CNameCollector();
ast.accept(col);
for (IASTName n : col.nameList) {
assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding);
}
}
}
static protected class CNameCollector extends ASTVisitor {
{
shouldVisitNames = true;
}
public List<IASTName> nameList = new ArrayList<IASTName>();
@Override
public int visit(IASTName name) {
nameList.add(name);
return PROCESS_CONTINUE;
}
public IASTName getName(int idx) {
if (idx < 0 || idx >= nameList.size())
return null;
return nameList.get(idx);
}
public int size() {
return nameList.size();
}
}
interface ITestStrategy { interface ITestStrategy {
IIndex getIndex(); IIndex getIndex();
void setUp() throws Exception; void setUp() throws Exception;
@ -227,30 +285,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public ICProject getCProject(); public ICProject getCProject();
public boolean isCompositeIndex(); public boolean isCompositeIndex();
} }
protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) {
assertInstance(b, IVariable.class);
IVariable variable = (IVariable) b;
assertQNEquals(qn, variable);
assertInstance(variable.getType(), expType);
if (expTypeQN != null) {
IType type= variable.getType();
assertInstance(type, IBinding.class);
assertQNEquals(expTypeQN, (IBinding) type);
}
}
protected static void assertTypeContainer(IType conType, String expQN, Class containerType, Class expContainedType, String expContainedTypeQN) {
assertInstance(conType, ITypeContainer.class);
assertInstance(conType, containerType);
IType containedType= ((ITypeContainer)conType).getType();
assertInstance(containedType, expContainedType);
if (expContainedTypeQN != null) {
assertInstance(containedType, IBinding.class);
assertQNEquals(expContainedTypeQN, (IBinding) containedType);
}
}
class SinglePDOMTestFirstASTStrategy implements ITestStrategy { class SinglePDOMTestFirstASTStrategy implements ITestStrategy {
private IIndex index; private IIndex index;
private ICProject cproject; private ICProject cproject;
@ -266,7 +301,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public ICProject getCProject() { public ICProject getCProject() {
return cproject; return cproject;
} }
@Override @Override
public StringBuilder[] getTestData() { public StringBuilder[] getTestData() {
return testData; return testData;
@ -293,7 +328,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); : CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle(); Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);
@ -330,7 +365,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() { public IIndex getIndex() {
return index; return index;
} }
@Override @Override
public boolean isCompositeIndex() { public boolean isCompositeIndex() {
return false; return false;
@ -379,7 +414,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); : CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle(); Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);
@ -390,7 +425,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString()); IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if (DEBUG) { if (DEBUG) {
System.out.println("Project PDOM: " + getName()); System.out.println("Project PDOM: " + getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@ -416,7 +451,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() { public IIndex getIndex() {
return index; return index;
} }
@Override @Override
public boolean isCompositeIndex() { public boolean isCompositeIndex() {
return false; return false;
@ -472,7 +507,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); : CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle(); Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0);
@ -499,7 +534,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
} }
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if (DEBUG) { if (DEBUG) {
System.out.println("Project PDOM: " + getName()); System.out.println("Project PDOM: " + getName());
((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@ -527,7 +562,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() { public IIndex getIndex() {
return index; return index;
} }
@Override @Override
public boolean isCompositeIndex() { public boolean isCompositeIndex() {
return false; return false;
@ -549,7 +584,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public ICProject getCProject() { public ICProject getCProject() {
return cproject; return cproject;
} }
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (index != null) { if (index != null) {
@ -582,7 +617,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(cproject); CCorePlugin.getIndexManager().reindex(cproject);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if (DEBUG) { if (DEBUG) {
System.out.println("Online: "+getName()); System.out.println("Online: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@ -598,17 +633,17 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
: CProjectHelper.createCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); : CProjectHelper.createCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
String content = testData[0].toString(); String content = testData[0].toString();
IFile file = TestSourceReader.createFile(referenced.getProject(), new Path("header.h"), content); IFile file = TestSourceReader.createFile(referenced.getProject(), new Path("header.h"), content);
IndexerPreferences.set(referenced.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); IndexerPreferences.set(referenced.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(referenced); CCorePlugin.getIndexManager().reindex(referenced);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if (DEBUG) { if (DEBUG) {
System.out.println("Referenced: "+getName()); System.out.println("Referenced: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter()); ((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter());
} }
return referenced; return referenced;
} }
@ -640,7 +675,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public StringBuilder[] getTestData() { public StringBuilder[] getTestData() {
return testData; return testData;
} }
@Override @Override
public boolean isCompositeIndex() { public boolean isCompositeIndex() {
return true; return true;
@ -650,7 +685,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
/** /**
* When a test is failing only for the strategy where the test data is split over * When a test is failing only for the strategy where the test data is split over
* multiple index fragments, we artificially fail the single fragment strategy also. * multiple index fragments, we artificially fail the single fragment strategy also.
* This is not ideal, but as both strategies behavior are typically the same, is * This is not ideal, but as both strategies behavior are typically the same, is
* quite rare. * quite rare.
*/ */
protected void fakeFailForSingle() { protected void fakeFailForSingle() {
@ -662,7 +697,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
/** /**
* When a test is failing only for the strategy where the test data is not split over * When a test is failing only for the strategy where the test data is not split over
* multiple index fragments, we artificially fail the single fragment strategy also. * multiple index fragments, we artificially fail the single fragment strategy also.
* This is not ideal, but as both strategies behavior are typically the same, is * This is not ideal, but as both strategies behavior are typically the same, is
* quite rare. * quite rare.
*/ */
protected void fakeFailForMultiProject() { protected void fakeFailForMultiProject() {

View file

@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -58,7 +59,6 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -1954,4 +1955,84 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class); ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class);
assertEquals("int", ASTTypeUtil.getType(tdef, true)); assertEquals("int", ASTTypeUtil.getType(tdef, true));
} }
// template<typename T, T v>
// struct integral_constant {
// static constexpr T value = v;
// typedef T value_type;
// typedef integral_constant<T, v> type;
// };
//
// typedef integral_constant<bool, true> true_type;
//
// typedef integral_constant<bool, false> false_type;
//
// template<typename T>
// class helper {
// typedef char one;
// typedef struct { char arr[2]; } two;
// template<typename U> struct Wrap_type {};
// template<typename U> static one test(Wrap_type<typename U::category>*);
// template<typename U> static two test(...);
// public: static const bool value = sizeof(test<T>(0)) == 1;
// };
//
// template<typename T>
// struct has_category : integral_constant<bool, helper<T>::value> {};
//
// template<typename Iterator, bool = has_category<Iterator>::value>
// struct traits {};
//
// template<typename Iterator>
// struct traits<Iterator, true> {
// typedef typename Iterator::value_type value_type;
// };
//
// struct tag {};
// struct C {
// typedef int value_type;
// typedef tag category;
// };
//
// template<typename It, typename Val = typename traits<It>::value_type>
// class A {
// };
//
// typedef A<C> type;
public void _testSFINAE_a() throws Exception {
checkBindings();
}
// template <bool B, typename T = void> struct enable_if { typedef T type; };
// template <typename T> struct enable_if<false, T> {};
//
// template <typename T> struct is_int { static const bool value = false; };
// template <> struct is_int<int> { static const bool value = true; };
//
// template <typename T> struct is_double { static const bool value = false; };
// template <> struct is_double<double> { static const bool value = true; };
//
// template <typename T, typename Enabled = void>
// struct A {
// static int get() { return 0; }
// };
//
// template<typename T>
// struct A<T, typename enable_if<is_double<T>::value>::type> {
// static int get() { return 1; }
// };
//
// template <typename T>
// struct A<T, typename enable_if<is_int<T>::value>::type> {
// static int get() { return 2; }
// };
// void test() {
// A<double>::get();
// A<int>::get();
// }
public void testSFINAE_b() throws Exception {
checkBindings();
}
} }