Skip to content

Commit b50ea2f

Browse files
committed
Also detect dependent parameter types of the form something<...,T,...>, not just T, closes #367
1 parent 928186e commit b50ea2f

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

source/cppfront.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,26 +3812,35 @@ class cppfront
38123812
//-----------------------------------------------------------------------
38133813
// Else handle ordinary parameters
38143814

3815-
auto unqid = std::get_if<type_id_node::unqualified>(&type_id.id);
3815+
auto param_type = print_to_string(type_id);
38163816

3817-
// If this parameter's name is an unqualified-id, check to see
3818-
// if it's the name of one of the template parameters
3819-
auto is_template_parameter_name = false;
3817+
// If there are template parameters, see if this parameter's name is an
3818+
// unqualified-id with a template parameter name, or mentions a template
3819+
// parameter as a template argument
3820+
auto is_dependent_parameter_type = false;
38203821
if (
3821-
unqid
3822-
&& current_declarations.back()
3822+
current_declarations.back()
38233823
&& current_declarations.back()->template_parameters
38243824
)
38253825
{
38263826
for (auto& tparam : current_declarations.back()->template_parameters->parameters)
38273827
{
3828-
assert(tparam);
3828+
assert(
3829+
tparam
3830+
&& tparam->name()
3831+
);
3832+
// For now just do a quick string match
3833+
auto tparam_name = tparam->name()->to_string(true);
38293834
if (
38303835
tparam->declaration->is_type()
3831-
&& tparam->declaration->has_name( *(*unqid)->identifier )
3836+
&& (
3837+
param_type == tparam_name
3838+
|| std::string_view{param_type}.find("<"+tparam_name) != std::string_view::npos
3839+
|| std::string_view{param_type}.find(","+tparam_name) != std::string_view::npos
3840+
)
38323841
)
38333842
{
3834-
is_template_parameter_name = true;
3843+
is_dependent_parameter_type = true;
38353844
}
38363845
}
38373846
}
@@ -3843,7 +3852,7 @@ class cppfront
38433852
if (
38443853
!is_returns
38453854
&& !type_id.is_wildcard()
3846-
&& !is_template_parameter_name
3855+
&& !is_dependent_parameter_type
38473856
)
38483857
{
38493858
switch (n.pass) {
@@ -3857,12 +3866,12 @@ class cppfront
38573866

38583867
if (
38593868
type_id.is_wildcard()
3860-
|| is_template_parameter_name
3869+
|| is_dependent_parameter_type
38613870
)
38623871
{
38633872
auto name = std::string{"auto"};
3864-
if (is_template_parameter_name) {
3865-
name = *(*unqid)->identifier;
3873+
if (is_dependent_parameter_type) {
3874+
name = param_type;
38663875
}
38673876
switch (n.pass) {
38683877
break;case passing_style::in : printer.print_cpp2( name+" const&", n.position() );
@@ -3912,7 +3921,7 @@ class cppfront
39123921
if (
39133922
!is_returns
39143923
&& !type_id.is_wildcard()
3915-
&& !is_template_parameter_name
3924+
&& !is_dependent_parameter_type
39163925
)
39173926
{
39183927
switch (n.pass) {

source/parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5124,7 +5124,7 @@ class parser
51245124
&& param->direction() != passing_style::inout
51255125
)
51265126
{
5127-
error("parameters scoped to a block/statement must be 'in' (the default) or 'inout'", false);
5127+
error("(temporary alpha limitation) parameters scoped to a block/statement must be 'in' (the default) or 'inout'", false);
51285128
return {};
51295129
}
51305130
}

0 commit comments

Comments
 (0)