[C++ PATCH] Core issue #226: Default template arguments in function templates

Doug Gregor doug.gregor@gmail.com
Wed Mar 28 12:21:00 GMT 2007


On 3/28/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> this looks good, but ...

Thanks for reviewing it.

> @@ -11346,6 +11374,23 @@ type_unification_real (tree tparms,
>               && !saw_undeduced++)
>             goto again;
>
> +          /* Core issue #226 (C++0x) [temp.deduct]:
> +
> +               If a template argument has not been deduced, its
> +               default template argument, if any, is used.  */
> +          if (TREE_PURPOSE (TREE_VEC_ELT (tparms, i)))
> +            {
>
> shouldn't that be protected with flag_cpp0x too?

If we're not in C++0x mode (flag_cpp0x) and the user tried to provide
a default template argument in a function template, TREE_PURPOSE will
be error_mark_node (that's set in check_default_tmpl_args when it
emits an error). So, the behavior will be the same whether or not we
check flag_cpp0x here. The danger is if we somehow missed a case in
check_default_tmpl_args (or it isn't getting called somewhere), in
which case we would silently permit C++0x behavior under -std=c++98.

I've typically been trying to minimize the number of places where we
check this flag, to minimize the differences between the C++98/03 and
C++0x code paths, in the hope that this will help us maintain more
consistency in the front end. So, I put in the checks for C++0x
features as early as possible (in the parser or its semantic
analysis), and then avoid checking for C++0x-specific tree codes or
behaviors throughout the rest of the compiler.

If you would prefer having a flag_cpp0x check added, that's fine. I
think the general principle of only checking C++0x features early and
where absolutely necessary will help us in the long run.

  Cheers,
  Doug



More information about the Gcc-patches mailing list