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

bug 90683 - syntax errors in template argument

This commit is contained in:
Andrew Niefer 2007-08-04 01:11:53 +00:00
parent 9577e25245
commit 1bec4f8d34
3 changed files with 52 additions and 51 deletions

View file

@ -175,31 +175,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 8.2-4):
template <class T>
struct S {
T *p;
};
S<int()> x; // typeid
S<int(1)> y; // expression (illformed)
--End Example]
*/
public void test8_2s4() { // TODO raised bug 90632
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T>\n"); //$NON-NLS-1$
buffer.append("struct S {\n"); //$NON-NLS-1$
buffer.append("T *p;\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("S<int()> x; // typeid\n"); //$NON-NLS-1$
buffer.append("S<int(1)> y; // expression (illformed)\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 8.2-7a):
class C { };
@ -559,25 +534,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.5.5.1-8b):
// Illformed, no diagnostic required
template <int I> void f(A<I>, A<I+10>);
template <int I> void f(A<I>, A<I+1+2+3+4>);
--End Example]
*/
public void test14_5_5_1s8b() {
StringBuffer buffer = new StringBuffer();
buffer.append("// Illformed, no diagnostic required\n"); //$NON-NLS-1$
buffer.append("template <int I> void f(A<I>, A<I+10>);\n"); //$NON-NLS-1$
buffer.append("template <int I> void f(A<I>, A<I+1+2+3+4>);\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.8.1-4):

View file

@ -3362,6 +3362,29 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 8.2-4):
template <class T>
struct S {
T *p;
};
S<int()> x; // typeid
S<int(1)> y; // expression (illformed)
--End Example]
*/
public void test8_2s4() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T>\n"); //$NON-NLS-1$
buffer.append("struct S {\n"); //$NON-NLS-1$
buffer.append("T *p;\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("S<int()> x; // typeid\n"); //$NON-NLS-1$
buffer.append("S<int(1)> y; // expression (illformed)\n"); //$NON-NLS-1$
//test is only for syntax, semantics are not checked here.
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 8.2-5):
void foo()
@ -9450,6 +9473,24 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.5.5.1-8b):
// Illformed, no diagnostic required
template <int I> void f(A<I>, A<I+10>);
template <int I> void f(A<I>, A<I+1+2+3+4>);
--End Example]
*/
public void test14_5_5_1s8b() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("// Illformed, no diagnostic required\n"); //$NON-NLS-1$
buffer.append("template <int I> void f(A<I>, A<I+10>);\n"); //$NON-NLS-1$
buffer.append("template <int I> void f(A<I>, A<I+1+2+3+4>);\n"); //$NON-NLS-1$
//test is only for syntax, semantics are not checked here.
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
}
/**
[--Start Example(CPP 14.5.5.2-5):
template<class T> struct A { A(); };

View file

@ -303,13 +303,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IToken mark = mark();
IASTTypeId typeId = typeId(false);
if (typeId != null) {
list.add(typeId);
completedArg = true;
} else {
backup(mark);
}
IASTTypeId typeId = typeId(false);
if (typeId == null) {
backup(mark);
} else if (LT(1) != IToken.tCOMMA && LT(1) != IToken.tGT && LT(1) != IToken.tEOC){
//didn't consume the whole argument, probably confused typeId with idExpression
//backup and try the assignmentExpression
backup(mark);
} else {
list.add(typeId);
completedArg = true;
}
if (!completedArg) {
try {
IASTExpression expression = assignmentExpression();