On Mar 23, 2018, Jason Merrill <ja...@redhat.com> wrote: > On Fri, Mar 23, 2018 at 3:38 PM, Alexandre Oliva <aol...@redhat.com> wrote: >> + /* Concepts allows 'auto' in template arguments, even multiple >> + 'auto's in a single argument.
> I think that's only intended for class templates; Aah, that explains a lot! Dang, it was so close! It actually makes sense; was there any discussion about standardizing this, with reasons to reject this construct, or is it just that we aren't there yet? I wouldn't be surprised if it were to appear in some future version of C++. > we should reject 'auto' as a template argument for function or > variable templates. Is this (in the patch below) the best spot to test for it? [PR c++/84979] reject auto in explicit tmpl args for tmpl-fn With concepts, we accept auto in explicit template arguments, but we should only accept them for template classes. Passing them to template functions is not allowed. So, reject it. Regstrapping on i686- and x86-64-linux-gnu, after a successful make check-c++-all. Ok to install if it passes? for gcc/cp/ChangeLog PR c++/84979 * semantics.c (finish_id_expression): Reject template args referencing auto for template fns. for gcc/testsuite/ChangeLog PR c++/84979 * g++.dg/concepts/pr84979.C: New. --- gcc/cp/semantics.c | 11 +++++++++-- gcc/testsuite/g++.dg/concepts/pr84979.C | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/pr84979.C diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 035e39515748..9b33234c8b73 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3528,8 +3528,15 @@ finish_id_expression (tree id_expression, /* If we have a template-id, then no further lookup is required. If the template-id was for a template-class, we will sometimes have a TYPE_DECL at this point. */ - else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR - || TREE_CODE (decl) == TYPE_DECL) + else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR) + { + if (flag_concepts && type_uses_auto (decl)) + { + *error_msg = "invalid use of %<auto%> in template argument for template function"; + return error_mark_node; + } + } + else if (TREE_CODE (decl) == TYPE_DECL) ; /* Look up the name. */ else diff --git a/gcc/testsuite/g++.dg/concepts/pr84979.C b/gcc/testsuite/g++.dg/concepts/pr84979.C new file mode 100644 index 000000000000..c70b3756f2b8 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr84979.C @@ -0,0 +1,9 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-fconcepts" } + +template<typename> void foo() {} + +void bar() +{ + foo<auto>(); // { dg-error "invalid|no match" } +} -- Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer