mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Bug 336426: Syntax failure in return type of function instance.
This commit is contained in:
parent
da432ec64b
commit
98d41710ac
2 changed files with 45 additions and 4 deletions
|
@ -5236,4 +5236,26 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
public void testFunctionTemplateSignatures_Bug335062() throws Exception {
|
public void testFunctionTemplateSignatures_Bug335062() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <bool B, class T = void> struct enable_if {
|
||||||
|
// typedef T type;
|
||||||
|
// };
|
||||||
|
// template <class T> struct enable_if<false, T> {};
|
||||||
|
//
|
||||||
|
// template <typename T> struct is_int {
|
||||||
|
// static const bool value = false;
|
||||||
|
// };
|
||||||
|
// template <> struct is_int<int> {
|
||||||
|
// static const bool value = true;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <typename T> typename enable_if<!is_int<T>::value>::type function(T);
|
||||||
|
// template <typename T> typename enable_if<is_int<T>::value>::type function(T);
|
||||||
|
//
|
||||||
|
// void g() {
|
||||||
|
// function(0); // ERROR HERE
|
||||||
|
// }
|
||||||
|
public void testSyntaxErrorInReturnTypeOfFunctionInstance_Bug336426() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1605,7 +1605,9 @@ public class CPPTemplates {
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
IBinding instance= instantiateFunctionTemplate(template, args, map);
|
IBinding instance= instantiateFunctionTemplate(template, args, map);
|
||||||
if (instance instanceof ICPPFunction) {
|
if (instance instanceof ICPPFunction) {
|
||||||
return (ICPPFunction) instance;
|
final ICPPFunction f = (ICPPFunction) instance;
|
||||||
|
if (isValidType(f.getType()))
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
|
@ -1917,10 +1919,27 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isValidType(IType t) {
|
static boolean isValidType(IType t) {
|
||||||
while (t instanceof ITypeContainer) {
|
for (;;) {
|
||||||
t = ((ITypeContainer) t).getType();
|
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) {
|
static boolean isValidArgument(ICPPTemplateArgument arg) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue