From 98d41710ac180047f9a3aeaf529a17cf69fc88ca Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 9 Feb 2011 16:24:23 +0000 Subject: [PATCH] Bug 336426: Syntax failure in return type of function instance. --- .../parser/tests/ast2/AST2TemplateTests.java | 22 +++++++++++++++ .../parser/cpp/semantics/CPPTemplates.java | 27 ++++++++++++++++--- 2 files changed, 45 insertions(+), 4 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 94298b930f4..28f5b455076 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 @@ -5236,4 +5236,26 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFunctionTemplateSignatures_Bug335062() throws Exception { parseAndCheckBindings(); } + + // template struct enable_if { + // typedef T type; + // }; + // template struct enable_if {}; + // + // template struct is_int { + // static const bool value = false; + // }; + // template <> struct is_int { + // static const bool value = true; + // }; + // + // template typename enable_if::value>::type function(T); + // template typename enable_if::value>::type function(T); + // + // void g() { + // function(0); // ERROR HERE + // } + public void testSyntaxErrorInReturnTypeOfFunctionInstance_Bug336426() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 6a037646433..6c670a4a8af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1605,7 +1605,9 @@ public class CPPTemplates { if (args != null) { IBinding instance= instantiateFunctionTemplate(template, args, map); if (instance instanceof ICPPFunction) { - return (ICPPFunction) instance; + final ICPPFunction f = (ICPPFunction) instance; + if (isValidType(f.getType())) + return f; } } } catch (DOMException e) { @@ -1917,10 +1919,27 @@ public class CPPTemplates { } static boolean isValidType(IType t) { - while (t instanceof ITypeContainer) { - t = ((ITypeContainer) t).getType(); + for (;;) { + if (t instanceof ISemanticProblem) { + return false; + } else if (t instanceof IFunctionType) { + IFunctionType ft= (IFunctionType) t; + for (IType parameterType : ft.getParameterTypes()) { + if (!isValidType(parameterType)) + return false; + } + t= ft.getReturnType(); + } else if (t instanceof ICPPPointerToMemberType) { + ICPPPointerToMemberType mptr= (ICPPPointerToMemberType) t; + if (!isValidType(mptr.getMemberOfClass())) + return false; + t= mptr.getType(); + } else if (t instanceof ITypeContainer) { + t= ((ITypeContainer) t).getType(); + } else { + return true; + } } - return !(t instanceof ISemanticProblem); } static boolean isValidArgument(ICPPTemplateArgument arg) {