From 73175131ff5baeb102739b017568324a4242e92b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 2 Apr 2010 07:42:34 +0000 Subject: [PATCH] Bug 305987. --- .../AutomatedIntegrationSuite.launch | 41 +++++++++++++++++++ .../core/parser/tests/ast2/AST2CPPTests.java | 10 +++++ .../dom/parser/cpp/GNUCPPSourceParser.java | 5 ++- .../dom/parser/cpp/semantics/CPPVisitor.java | 14 ++++--- 4 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/AutomatedIntegrationSuite.launch diff --git a/core/org.eclipse.cdt.core.tests/AutomatedIntegrationSuite.launch b/core/org.eclipse.cdt.core.tests/AutomatedIntegrationSuite.launch new file mode 100644 index 00000000000..c3c18773bd6 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/AutomatedIntegrationSuite.launch @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 64cad41a33e..05d626ddf85 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 @@ -8329,6 +8329,16 @@ public class AST2CPPTests extends AST2BaseTest { assertNull(x.getType()); } + // struct A { auto a = 1; }; // Auto-typed non-static fields are not allowed. + // struct B { static auto b = 1; }; // Auto-typed static fields are ok. + public void testAutoType_305987() throws Exception { + String code= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + ICPPVariable a= bh.assertNonProblem("a =", 1); + assertNull(a.getType()); + ICPPVariable b= bh.assertNonProblem("b =", 1); + } + // auto fpif1(int)->int(*)(int) // auto fpif2(int)->int(*)(int) {} public void testNewFunctionDeclaratorSyntax_305972() throws Exception { 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 da044f9075c..a6faacca679 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 @@ -2143,12 +2143,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * This function parses a declaration specifier sequence, as according to * the ANSI C++ specification. * declSpecifier : - * "auto" | "register" | "static" | "extern" | "mutable" | + * "register" | "static" | "extern" | "mutable" | * "inline" | "virtual" | "explicit" | * "typedef" | "friend" | * "const" | "volatile" | * "short" | "long" | "signed" | "unsigned" | "int" | - * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | + * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | + * "auto" | * ("typename")? name | * { "class" | "struct" | "union" } classSpecifier | * {"enum"} enumSpecifier diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 3b6d66ad118..6837002634a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -191,7 +191,7 @@ public class CPPVisitor extends ASTQueries { public static final String TYPE_INFO= "type_info"; //$NON-NLS-1$ private static final String INITIALIZER_LIST = "initializer_list"; //$NON-NLS-1$ // Thread-local set of DeclSpecifiers for which auto types are being created. - // Used for preventing infinite recursion while processing invalid self-referring + // Used to prevent infinite recursion while processing invalid self-referencing // auto-type declarations. private static final ThreadLocal> autoTypeDeclSpecs = new ThreadLocal>() { @@ -1792,6 +1792,10 @@ public class CPPVisitor extends ASTQueries { if (declSpec instanceof ICPPASTSimpleDeclSpecifier && ((ICPPASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_auto) { + if (declarator instanceof ICPPASTFunctionDeclarator) { + return createAutoFunctionType(declSpec, (ICPPASTFunctionDeclarator) declarator); + } + parent = parent.getParent(); if (parent instanceof ICPPASTNewExpression) { IASTInitializer initializer = ((ICPPASTNewExpression) parent).getInitializer(); @@ -1799,6 +1803,10 @@ public class CPPVisitor extends ASTQueries { if (arguments.length == 1) { initClause = arguments[0]; } + } else if (parent instanceof IASTCompositeTypeSpecifier && + declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) { + // Non-static auto-typed class members are not allowed. + return null; } return createAutoType(initClause, declSpec, declarator); } @@ -1825,10 +1833,6 @@ public class CPPVisitor extends ASTQueries { private static IType createAutoType(IASTNode initClause, IASTDeclSpecifier declSpec, IASTDeclarator declarator) { // C++0x: 7.1.6.4 - if (declarator instanceof ICPPASTFunctionDeclarator) { - return createAutoFunctionType(declSpec, (ICPPASTFunctionDeclarator) declarator); - } - if (!autoTypeDeclSpecs.get().add(declSpec)) { // Detected a self referring auto type, e.g.: auto x = x; return null;