summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-12-14 22:08:04 (EST)
committer Sergey Prigogin2013-12-16 01:34:04 (EST)
commitebc858ec44b4ad8f58c15403a7d098b4b9f4f5d0 (patch)
tree60866b55b07b1a38e1dba3671a55e939737c416e
parentdd7dde956f0c260a24b0fc793fb0246b51f24685 (diff)
downloadorg.eclipse.cdt-ebc858ec44b4ad8f58c15403a7d098b4b9f4f5d0.zip
org.eclipse.cdt-ebc858ec44b4ad8f58c15403a7d098b4b9f4f5d0.tar.gz
org.eclipse.cdt-ebc858ec44b4ad8f58c15403a7d098b4b9f4f5d0.tar.bz2
Bug 419301 - Operator overloading confuses CDT (with boost)refs/changes/33/19833/3
Change-Id: I9f136577e8e64227d024ba6544017439f1ed2260 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/19833 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java51
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java25
3 files changed, 69 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index 3042996..1209dfc 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -2403,4 +2403,55 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
IType T = getBindingFromASTName("T", 1);
assertEquals("int", ASTTypeUtil.getType(T));
}
+
+ // template <class T, class U>
+ // struct multipliable2
+ // {
+ // friend T operator *(const U& lhs, const T& rhs);
+ // };
+ //
+ // template <class T>
+ // struct multipliable1
+ // {
+ // friend T operator *(const T& lhs, const T& rhs);
+ // };
+
+ // #include "header.h"
+ // struct overloaded : multipliable1<overloaded> {};
+ //
+ // int foo(overloaded);
+ //
+ // int main()
+ // {
+ // overloaded c, d;
+ // foo(c * d);
+ // }
+ public void testFriendFunctionOfClassSpecialization_419301a() throws Exception {
+ checkBindings();
+ }
+
+ // template <class T, class U>
+ // struct multipliable2
+ // {
+ // friend T operator *(const U& lhs, const T& rhs);
+ // };
+ //
+ // template <class T>
+ // struct multipliable1
+ // {
+ // friend T operator *(const T& lhs, const T& rhs) {}
+ // };
+
+ // #include "header.h"
+ // struct overloaded : multipliable1 <overloaded> {};
+ //
+ // int foo(overloaded);
+ //
+ // int main() {
+ // overloaded c, d;
+ // foo(c * d);
+ // }
+ public void testFriendFunctionOfClassSpecialization_419301b() throws Exception {
+ checkBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java
index e27d0f3..7f49e57 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java
@@ -367,7 +367,9 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
@Override
public IBinding[] getFriends(IASTNode point) {
- // Not yet supported.
+ ICPPClassScope scope= getCompositeScope();
+ if (scope instanceof ICPPClassSpecializationScope)
+ return ((ICPPClassSpecializationScope) scope).getFriends(point);
return IBinding.EMPTY_BINDING_ARRAY;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index 266ba2d..6d7ae1e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -21,6 +21,8 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@@ -1041,17 +1043,20 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
} else if (parentNode instanceof ICPPASTFunctionDeclarator) {
+ IASTDeclSpecifier declSpec = null;
if (parentNode.getParent() instanceof IASTSimpleDeclaration) {
- IASTSimpleDeclaration grandparentNode = (IASTSimpleDeclaration) parentNode.getParent();
- if (grandparentNode.getDeclSpecifier() instanceof ICPPASTDeclSpecifier) {
- if (((ICPPASTDeclSpecifier) grandparentNode.getDeclSpecifier()).isFriend()) {
- pdomName.setIsFriendSpecifier();
- PDOMName enclClassName = (PDOMName) pdomName.getEnclosingDefinition();
- if (enclClassName != null) {
- PDOMBinding enclClassBinding = enclClassName.getBinding();
- if (enclClassBinding instanceof PDOMCPPClassType) {
- ((PDOMCPPClassType) enclClassBinding).addFriend(new PDOMCPPFriend(this, pdomName));
- }
+ declSpec = ((IASTSimpleDeclaration) parentNode.getParent()).getDeclSpecifier();
+ } else if (parentNode.getParent() instanceof IASTFunctionDefinition) {
+ declSpec = ((IASTFunctionDefinition) parentNode.getParent()).getDeclSpecifier();
+ }
+ if (declSpec instanceof ICPPASTDeclSpecifier) {
+ if (((ICPPASTDeclSpecifier) declSpec).isFriend()) {
+ pdomName.setIsFriendSpecifier();
+ PDOMName enclClassName = (PDOMName) pdomName.getEnclosingDefinition();
+ if (enclClassName != null) {
+ PDOMBinding enclClassBinding = enclClassName.getBinding();
+ if (enclClassBinding instanceof PDOMCPPClassType) {
+ ((PDOMCPPClassType) enclClassBinding).addFriend(new PDOMCPPFriend(this, pdomName));
}
}
}