Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2014-01-22 08:07:52 +0000
committerSergey Prigogin2014-01-22 19:10:12 +0000
commit4272059ea211ed70bfb1a29609ba24183f6ad73a (patch)
tree23dc37e0836a2d4148ea3d111d0041f00b45e7ba
parent23c1747ebc826933c3769a4a401fe33a971fd964 (diff)
downloadorg.eclipse.cdt-4272059ea211ed70bfb1a29609ba24183f6ad73a.tar.gz
org.eclipse.cdt-4272059ea211ed70bfb1a29609ba24183f6ad73a.tar.xz
org.eclipse.cdt-4272059ea211ed70bfb1a29609ba24183f6ad73a.zip
Bug 424765 - Implicit conversion from lambda to function pointer not
recongized Change-Id: I33ae542ef428005dd2eaa5ca8010f53f04f54a27 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/20926 Tested-by: Hudson CI 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/core/parser/tests/ast2/AST2CPPTests.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java29
2 files changed, 29 insertions, 9 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 db5ab1a869f..aabb70de4a6 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
@@ -10479,4 +10479,13 @@ public class AST2CPPTests extends AST2TestBase {
public void testFieldWithSameNameAsClass_326750() throws Exception {
parseAndCheckBindings();
}
+
+ // void waldo(void(*)());
+ //
+ // int main() {
+ // waldo([](){});
+ // }
+ public void testConversionFromLambdaToFunctionPointer_424765() throws Exception {
+ parseAndCheckBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
index a5d91072c07..fe1a1c4b590 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
@@ -61,6 +61,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
@@ -99,31 +100,41 @@ public class SemanticUtil {
/**
* Returns an array of ICPPMethod objects representing all conversion operators
- * declared by the specified class. This does not include inherited methods. Conversion
- * operators cannot be implicit.
+ * declared by the specified class, and the implicitly generated conversion
+ * operator for a closure type. This does not include inherited methods.
* @param clazz
* @return an array of conversion operators.
*/
public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz, IASTNode point) throws DOMException {
- ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
+ ICPPMethod[] conversionOps= ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
if (clazz instanceof ICPPDeferredClassInstance) {
clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition();
}
- ICPPMethod[] decs= ClassTypeHelper.getDeclaredMethods(clazz, point);
- if (decs != null) {
- for (ICPPMethod method : decs) {
+ ICPPMethod[] methods;
+ // For a closure type, getDeclaredMethods() does not return the conversion
+ // operator because it is implicitly generated. We can use getMethods()
+ // however as a closure type does not have base classes.
+ // A new API ICPPClosureType.getNoninheritedMethods() might be more
+ // appropriate here.
+ if (clazz instanceof CPPClosureType) {
+ methods = ClassTypeHelper.getMethods(clazz, point);
+ } else {
+ methods = ClassTypeHelper.getDeclaredMethods(clazz, point);
+ }
+ if (methods != null) {
+ for (ICPPMethod method : methods) {
if (isConversionOperator(method)) {
- methods= ArrayUtil.append(methods, method);
+ conversionOps= ArrayUtil.append(conversionOps, method);
}
}
}
- return methods;
+ return conversionOps;
}
/**
* Returns an array of ICPPMethod objects representing all conversion operators
* declared by the specified class and its ancestors. This includes inherited
- * methods. Conversion operators cannot be implicit.
+ * methods, and the implicitly generated conversion operator for a closure type.
* @param clazz
* @return an array of conversion operators.
*/

Back to the top