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

Fixed 86282 [Parser] New expression for array of 10 pointers to funct...

Fixed 90640 [Parser] invalid syntax error with cpp 8.2-3
Fixed 90671 [Parser] [Ambiguity]invalid syntax error on cpp 14.3-2
This commit is contained in:
John Camelon 2005-06-01 20:30:59 +00:00
parent 8e99ab5565
commit 121b48c3d1
6 changed files with 76 additions and 57 deletions

View file

@ -141,34 +141,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 8.2-3):
// #include <cstddef>
char *p;
void *operator new(size_t, int);
void foo() {
const int x = 63;
new (int(*p)) int; // newplacement expression
new (int(*[x])); // new typeid
}
--End Example]
*/
public void test8_2s3() { // TODO raised bug 90640
StringBuffer buffer = new StringBuffer();
buffer.append("// #include <cstddef>\n"); //$NON-NLS-1$
buffer.append("char *p;\n"); //$NON-NLS-1$
buffer.append("void *operator new(size_t, int);\n"); //$NON-NLS-1$
buffer.append("void foo() {\n"); //$NON-NLS-1$
buffer.append("const int x = 63;\n"); //$NON-NLS-1$
buffer.append("new (int(*p)) int; // newplacement expression\n"); //$NON-NLS-1$
buffer.append("new (int(*[x])); // new typeid\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 8.2-4):
@ -268,31 +241,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.3-2):
template<class T> void f();
template<int I> void f();
void g()
{
f<int()>(); // int() is a typeid:call the first f()
}
--End Example]
*/
public void test14_3s2() { // TODO raised bug 90671
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> void f();\n"); //$NON-NLS-1$
buffer.append("template<int I> void f();\n"); //$NON-NLS-1$
buffer.append("void g()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("f<int()>(); // int() is a typeid:call the first f()\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.5.3-1):

View file

@ -12532,4 +12532,50 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
buffer.append( "}");
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 8.2-3):
// #include <cstddef>
char *p;
void *operator new(size_t, int);
void foo() {
const int x = 63;
new (int(*p)) int; // newplacement expression
new (int(*[x])); // new typeid
}
--End Example]
*/
public void test8_2s3() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("// #include <cstddef>\n"); //$NON-NLS-1$
buffer.append("char *p;\n"); //$NON-NLS-1$
buffer.append("void *operator new(size_t, int);\n"); //$NON-NLS-1$
buffer.append("void foo() {\n"); //$NON-NLS-1$
buffer.append("const int x = 63;\n"); //$NON-NLS-1$
buffer.append("new (int(*p)) int; // newplacement expression\n"); //$NON-NLS-1$
buffer.append("new (int(*[x])); // new typeid\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
}
/**
[--Start Example(CPP 14.3-2):
template<class T> void f();
template<int I> void f();
void g()
{
f<int()>(); // int() is a typeid:call the first f()
}
--End Example]
*/
public void test14_3s2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> void f();\n"); //$NON-NLS-1$
buffer.append("template<int I> void f();\n"); //$NON-NLS-1$
buffer.append("void g()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("f<int()>(); // int() is a typeid:call the first f()\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
}

View file

@ -102,6 +102,13 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class AST2CPPTests extends AST2BaseTest {
public void testBug86282() throws Exception {
IASTTranslationUnit tu = parse( "void foo() { int (* f[])() = new (int (*[10])()); }", ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertNoProblemBindings( col );
}
public void testBug75858() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append( "bool f() {\n" );
@ -3990,7 +3997,6 @@ public class AST2CPPTests extends AST2BaseTest {
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertNoProblemBindings(col);
}
protected void assertNoProblemBindings(CPPNameCollector col) {

View file

@ -102,10 +102,20 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator {
}
}
if( getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
nestedDeclarator == null )
{
if( name != null ) if( !name.accept( action ) ) return false;
if( getParent() instanceof IASTDeclarator )
{
IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent();
while( outermostDeclarator.getParent() instanceof IASTDeclarator )
outermostDeclarator = (IASTDeclarator) outermostDeclarator.getParent();
if( outermostDeclarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR )
if( name != null ) if( !name.accept( action ) ) return false;
}
else
if( name != null ) if( !name.accept( action ) ) return false;
}
if( nestedDeclarator != null ) if( !nestedDeclarator.accept( action ) ) return false;

View file

@ -110,7 +110,16 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator {
if( getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
nestedDeclarator == null )
{
if( name != null ) if( !name.accept( action ) ) return false;
if( getParent() instanceof IASTDeclarator )
{
IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent();
while( outermostDeclarator.getParent() instanceof IASTDeclarator )
outermostDeclarator = (IASTDeclarator) outermostDeclarator.getParent();
if( outermostDeclarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR )
if( name != null ) if( !name.accept( action ) ) return false;
}
else
if( name != null ) if( !name.accept( action ) ) return false;
}
if( nestedDeclarator != null ) if( !nestedDeclarator.accept( action ) ) return false;

View file

@ -1126,7 +1126,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// CASE: new (typeid-not-looking-as-placement) ...
// the first expression in () is not a placement
// - then it has to be typeId
typeId = typeId(true);
typeId = typeId(false);
lastOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes.size() > 0) {
templateIdScopes.pop();