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

Syntax error in template definition (template id ambiguity), bug 228118.

This commit is contained in:
Markus Schorn 2008-04-22 10:45:00 +00:00
parent 3aa200e4e0
commit 4db6ea5e78
2 changed files with 55 additions and 21 deletions

View file

@ -1249,15 +1249,15 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod[] methods = ((ICPPClassScope)A.getCompositeScope()).getImplicitMethods();
assertNotNull(methods);
int count=0;
for(int i=0; i<methods.length; i++)
count+= methods[i].getName().startsWith("~") ? 1 : 0;
for (ICPPMethod method : methods)
count+= method.getName().startsWith("~") ? 1 : 0;
assertEquals(line, 0, count);
methods = A.getDeclaredMethods();
assertNotNull(methods);
count=0;
for(int i=0; i<methods.length; i++)
count+= methods[i].getName().startsWith("~") ? 1 : 0;
for (ICPPMethod method : methods)
count+= method.getName().startsWith("~") ? 1 : 0;
assertEquals(line, 1, count);
}
}
@ -1276,15 +1276,15 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod[] methods = ((ICPPClassScope)A.getCompositeScope()).getImplicitMethods();
assertNotNull(methods);
int count=0;
for(int i=0; i<methods.length; i++)
count+= methods[i].getName().startsWith("~") ? 1 : 0;
for (ICPPMethod method : methods)
count+= method.getName().startsWith("~") ? 1 : 0;
assertEquals(line, 1, count);
methods = A.getDeclaredMethods();
assertNotNull(methods);
count=0;
for(int i=0; i<methods.length; i++)
count+= methods[i].getName().startsWith("~") ? 1 : 0;
for (ICPPMethod method : methods)
count+= method.getName().startsWith("~") ? 1 : 0;
assertEquals(line, 0, count);
}
}
@ -1397,8 +1397,8 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod[] methods = ((ICPPClassScope)A.getCompositeScope()).getImplicitMethods();
assertNotNull(methods);
int count=0;
for(int i=0; i<methods.length; i++) {
boolean eq= Arrays.equals(methods[i].getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
for (ICPPMethod method : methods) {
boolean eq= Arrays.equals(method.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
count+= eq ? 1 : 0;
}
@ -1407,8 +1407,8 @@ public class AST2CPPTests extends AST2BaseTest {
methods = A.getDeclaredMethods();
assertNotNull(methods);
count=0;
for(int i=0; i<methods.length; i++) {
boolean eq= Arrays.equals(methods[i].getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
for (ICPPMethod method : methods) {
boolean eq= Arrays.equals(method.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
count+= eq ? 1 : 0;
}
@ -1430,8 +1430,8 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod[] methods = ((ICPPClassScope)A.getCompositeScope()).getImplicitMethods();
assertNotNull(methods);
int count=0;
for(int i=0; i<methods.length; i++) {
boolean eq= Arrays.equals(methods[i].getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
for (ICPPMethod method : methods) {
boolean eq= Arrays.equals(method.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
count+= eq ? 1 : 0;
}
@ -1440,8 +1440,8 @@ public class AST2CPPTests extends AST2BaseTest {
methods = A.getDeclaredMethods();
assertNotNull(methods);
count=0;
for(int i=0; i<methods.length; i++) {
boolean eq= Arrays.equals(methods[i].getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
for (ICPPMethod method : methods) {
boolean eq= Arrays.equals(method.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray());
count+= eq ? 1 : 0;
}
@ -2284,8 +2284,7 @@ public class AST2CPPTests extends AST2BaseTest {
// check the result
HashSet result= new HashSet();
for (int i = 0; i < bs.length; i++) {
IBinding binding = bs[i];
for (IBinding binding : bs) {
result.add(binding.getName());
}
assertTrue(result.contains("a1"));
@ -5373,7 +5372,26 @@ public class AST2CPPTests extends AST2BaseTest {
bh.assertNonProblem("relayIndex >", 10);
bh.assertNonProblem("numRelays )", 9);
}
// template<typename A, typename B>
// struct and_ : public integral_constant<bool, (A::value && B::value)> {
// };
// template<typename A, typename B>
// struct or_ : public integral_constant<bool, (A::value || B::value)> {
// };
// template <class T> struct is_pod
// : integral_constant<bool, (is_integral<T>::value ||
// is_floating_point<T>::value ||
// is_pointer<T>::value)> { };
//
// typedef base::integral_constant<bool,
// (base::has_trivial_copy<value_type>::value &&
// base::has_trivial_destructor<value_type>::value)>
// realloc_ok;
public void testTemplateIDAmbiguity_Bug228118() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP);
}
// namespace ns {
// class cl {};
// void func(cl c);

View file

@ -171,6 +171,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private int templateCount = 0;
private int functionBodyCount= 0;
private int templateArgListCount= 0;
private int preventLogicalOperatorInTemplateID;
protected CPPASTTranslationUnit translationUnit;
@ -331,6 +332,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return list;
}
/**
* To disambiguate between logical expressions and template id's in some situations
* we forbid the usage of the logical operators '&&' or '||' within template ids.
* @throws EndOfFileException
* @since 5.0
*/
protected final ITokenDuple nameWithoutLogicalOperatorInTemplateID() throws BacktrackException, EndOfFileException {
preventLogicalOperatorInTemplateID++;
try {
return name();
}
finally {
preventLogicalOperatorInTemplateID--;
}
}
/**
* Parse a name.
* name ::= ("::")? name2 ("::" name2)*
@ -415,7 +431,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
@Override
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
final IASTExpression expr= super.conditionalExpression();
if (templateArgListCount > 0) {
if (templateArgListCount > 0 && preventLogicalOperatorInTemplateID > 0) {
// bug 104706, don't allow usage of logical operators in template argument lists.
if (expr instanceof IASTConditionalExpression) {
final ASTNode node = (ASTNode) expr;
@ -1744,7 +1760,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
protected IASTName idExpression() throws EndOfFileException, BacktrackException {
IASTName name = null;
try {
name = createName(name());
name = createName(nameWithoutLogicalOperatorInTemplateID());
} catch (BacktrackException bt) {
IToken mark = mark();
if (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER) {