Skip to content

Commit

Permalink
Generate valid C# for default params in specialisations
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Aug 29, 2021
1 parent 0255eb7 commit 4d4505e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Generator/Passes/HandleDefaultParamValuesPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HandleDefaultParamValuesPass : TranslationUnitPass
new Dictionary<DeclarationContext, List<Function>>();

public HandleDefaultParamValuesPass()
=> VisitOptions.ResetFlags(VisitFlags.ClassMethods);
=> VisitOptions.ResetFlags(VisitFlags.ClassMethods | VisitFlags.ClassTemplateSpecializations);

public override bool VisitTranslationUnit(TranslationUnit unit)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ private static Method GetExtensionMethodForDependentPointer(Method specializedMe
foreach (var parameter in extensionMethod.Parameters)
{
var qualType = parameter.QualifiedType;
if (parameter.DefaultArgument != null)
{
Type type = qualType.Type.Desugar(resolveTemplateSubstitution: false);
type = (type.GetFinalPointee() ?? type).Desugar(
resolveTemplateSubstitution: false);
if (type is TemplateParameterSubstitutionType)
parameter.DefaultArgument = null;
}
RemoveTemplateSubstitution(ref qualType);
parameter.QualifiedType = qualType;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/CSharp/CSharpTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ T IndependentFields<T>::staticDependent(const T& t)
return t;
}

template <typename T>
template <typename AdditionalDependentType>
void IndependentFields<T>::usesAdditionalDependentType(AdditionalDependentType additionalDependentType)
{
}

template <typename T>
float IndependentFields<T>::getIndependent()
{
Expand Down Expand Up @@ -176,7 +182,7 @@ class DependentValueFields : public Base<T>
};

template <typename T>
DependentValueFields<T>::DependentValueFields()
DependentValueFields<T>::DependentValueFields() : unionField(0), dependentFunctionPointerField(0)
{
}

Expand All @@ -186,7 +192,7 @@ DependentValueFields<T>::~DependentValueFields()
}

template <typename T>
DependentValueFields<T>::DependentValueFields(IndependentFields<T> i)
DependentValueFields<T>::DependentValueFields(IndependentFields<T> i) : DependentValueFields()
{
}

Expand Down

0 comments on commit 4d4505e

Please sign in to comment.