From 45d8d40d087ea5cd6d6c93677102d963262000a6 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 28 Mar 2011 09:38:57 +0000 Subject: [PATCH] Bug 339977: void f(void) in template argument deduction. --- .../parser/tests/ast2/AST2TemplateTests.java | 14 +++++++++++ .../core/dom/parser/cpp/CPPFunctionType.java | 25 ++++++++----------- .../parser/cpp/semantics/SemanticUtil.java | 10 ++++++++ .../semantics/TemplateArgumentDeduction.java | 2 ++ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 1ab0a7cb5d4..34fc0218c47 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5278,4 +5278,18 @@ public class AST2TemplateTests extends AST2BaseTest { public void testVariadicFunctionTemplate_Bug333389() throws Exception { parseAndCheckBindings(); } + + // template void f(T(*)()); + // template void g(T(*)(void)); + // void v1(); + // void v2(void); + // void test() { + // f(v1); + // f(v2); + // g(v1); + // g(v2); + // } + public void testFunctionWithVoidParamInTypeDeduction() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index 57e58e68e02..413d1f954aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -63,24 +63,21 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { //constructors & destructors have null return type if ((returnType == null) ^ (ft.getReturnType() == null)) return false; - else if (returnType != null && ! returnType.isSameType(ft.getReturnType())) + + if (returnType != null && ! returnType.isSameType(ft.getReturnType())) return false; - if (parameters.length == 1 && fps.length == 0) { - if (!SemanticUtil.isVoidType(parameters[0])) - return false; - } else if (fps.length == 1 && parameters.length == 0) { - if (!SemanticUtil.isVoidType(fps[0])) - return false; - } else if (parameters.length != fps.length) { - return false; - } else { + if (parameters.length == fps.length) { for (int i = 0; i < parameters.length; i++) { - if (parameters[i] == null || ! parameters[i].isSameType(fps[i])) + if (parameters[i] == null || !parameters[i].isSameType(fps[i])) return false; } - } - + } else { + if (!SemanticUtil.isEmptyParameterList(parameters) + || !SemanticUtil.isEmptyParameterList(fps)) { + return false; + } + } return true; } return false; 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 3d83207ba6a..7513e44aec7 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 @@ -534,6 +534,16 @@ public class SemanticUtil { return false; } + public static boolean isEmptyParameterList(IType[] parameters) { + if (parameters.length == 0) { + return true; + } + if (parameters.length == 1 && isVoidType(parameters[0])) { + return true; + } + return false; + } + /** * Calculates the number of edges in the inheritance path of type to * ancestorToFind, returning -1 if no inheritance relationship is found. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index b2a6d30da84..b267c76ff27 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -816,6 +816,8 @@ public class TemplateArgumentDeduction { IType[] pParams = ftp.getParameterTypes(); IType[] aParams = fta.getParameterTypes(); if (pParams.length != aParams.length) { + if (SemanticUtil.isEmptyParameterList(pParams) && SemanticUtil.isEmptyParameterList(aParams)) + return true; if (pParams.length == 0 || pParams.length > aParams.length + 1) return false; IType lastPParam= pParams[pParams.length - 1];