mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
bug 90683 - syntax errors in template argument
This commit is contained in:
parent
9577e25245
commit
1bec4f8d34
3 changed files with 52 additions and 51 deletions
|
@ -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):
|
[--Start Example(CPP 8.2-7a):
|
||||||
class C { };
|
class C { };
|
||||||
|
@ -559,25 +534,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
||||||
} catch (Exception e) {
|
} 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):
|
[--Start Example(CPP 14.8.1-4):
|
||||||
|
|
|
@ -3362,6 +3362,29 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
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):
|
[--Start Example(CPP 8.2-5):
|
||||||
void foo()
|
void foo()
|
||||||
|
@ -9450,6 +9473,24 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
|
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
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):
|
[--Start Example(CPP 14.5.5.2-5):
|
||||||
template<class T> struct A { A(); };
|
template<class T> struct A { A(); };
|
||||||
|
|
|
@ -303,13 +303,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
|
|
||||||
IASTTypeId typeId = typeId(false);
|
IASTTypeId typeId = typeId(false);
|
||||||
if (typeId != null) {
|
if (typeId == null) {
|
||||||
list.add(typeId);
|
backup(mark);
|
||||||
completedArg = true;
|
} else if (LT(1) != IToken.tCOMMA && LT(1) != IToken.tGT && LT(1) != IToken.tEOC){
|
||||||
} else {
|
//didn't consume the whole argument, probably confused typeId with idExpression
|
||||||
backup(mark);
|
//backup and try the assignmentExpression
|
||||||
}
|
backup(mark);
|
||||||
|
} else {
|
||||||
|
list.add(typeId);
|
||||||
|
completedArg = true;
|
||||||
|
}
|
||||||
if (!completedArg) {
|
if (!completedArg) {
|
||||||
try {
|
try {
|
||||||
IASTExpression expression = assignmentExpression();
|
IASTExpression expression = assignmentExpression();
|
||||||
|
|
Loading…
Add table
Reference in a new issue