From 2e36c7ca14f463d052f6c149c9b2a10bd3814936 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 5 Jan 2012 08:39:43 +0100 Subject: [PATCH] Bug 367590: Destructor with wrong name. --- .../core/parser/tests/ast2/AST2CPPTests.java | 23 ++++++++++++++++++- .../dom/parser/cpp/GNUCPPSourceParser.java | 18 +++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index ed79ab1c023..3a3d954fae9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ package org.eclipse.cdt.core.parser.tests.ast2; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.XVALUE; +import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import java.io.BufferedReader; import java.io.IOException; @@ -9625,4 +9626,24 @@ public class AST2CPPTests extends AST2BaseTest { IBinding ctor= bh.assertNonProblem("E(){}", 1); assertTrue(ctor instanceof ICPPConstructor); } + + // struct S; + // struct S { + // S(); + // ~S(); + // T(); + // ~T(); + // }; + public void testErrorForDestructorWithWrongName_367590() throws Exception { + IASTTranslationUnit tu= parse(getAboveComment(), CPP, false, false); + IASTCompositeTypeSpecifier S; + IASTProblemDeclaration p; + IASTSimpleDeclaration s; + + S= getCompositeType(tu, 1); + s= getDeclaration(S, 0); + s= getDeclaration(S, 1); + p= getDeclaration(S, 2); + p= getDeclaration(S, 3); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 5587d4346f3..8b73bb6d741 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2011 IBM Corporation and others. + * Copyright (c) 2002, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -3211,17 +3211,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (name instanceof ICPPASTConversionName) return; - // accept destructor - final char[] nchars= name.getLookupKey(); - if (nchars.length > 0 && nchars[0] == '~') - return; if (opt == DeclarationOptions.CPP_MEMBER) { - // accept constructor within class body - if (CharArrayUtils.equals(nchars, currentClassName)) - return; + // Accept constructor and destructor within class body + final char[] nchars= name.getLookupKey(); + if (nchars.length > 0 && currentClassName != null) { + final int start= nchars[0] == '~' ? 1 : 0; + if (CharArrayUtils.equals(nchars, start, nchars.length-start, currentClassName)) + return; + } } else if (isQualified) { - // accept qualified constructor outside of class body + // Accept qualified constructor or destructor outside of class body return; } }