From 6cb90b0eb6e0d125a62b6294e524df8f91552dc0 Mon Sep 17 00:00:00 2001 From: Thomas Corbat Date: Sat, 18 Aug 2012 19:58:40 -0700 Subject: [PATCH] Bug 380141 - Support for Extended Friend Declarations Syntactic recognition of extended friend declarations. Approach is to allow declarations to have no declarator if they are named type specifiers and have friend as a declaration specifier. Change-Id: Id49afaadc4fd8b1cd10b398977ca6db252a9e799 --- .../core/parser/tests/ast2/AST2CPPTests.java | 26 +++++++++++++++++++ .../dom/parser/cpp/GNUCPPSourceParser.java | 4 +++ 2 files changed, 30 insertions(+) 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 0c40d13cc63..7465d5db67b 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 @@ -11,6 +11,7 @@ * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -9742,4 +9743,29 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(1, declarations.length); assertEquals(bh.findName("S", 1), declarations[0]); } + + // struct F {}; + // struct S { + // friend F; + // }; + public void testFriendClass() throws Exception { + parseAndCheckBindings(); + } + + // struct F {}; + // typedef F T; + // struct S { + // friend T; + // }; + public void testFriendTypedef() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct T { + // friend P; + // }; + public void testFriendTemplateParameter() throws Exception { + parseAndCheckBindings(); + } } 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 2c960038b66..de1972896ff 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 @@ -13,6 +13,7 @@ * Mike Kucera (IBM) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -2323,6 +2324,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTElaboratedTypeSpecifier) { return ((IASTElaboratedTypeSpecifier) declSpec).getKind() != IASTElaboratedTypeSpecifier.k_enum; + } else if (declSpec instanceof ICPPASTNamedTypeSpecifier && + ((ICPPASTNamedTypeSpecifier) declSpec).isFriend()) { + return true; } return super.isLegalWithoutDtor(declSpec); }