This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix ICE on invalid variable template instantiation (PR c++/72759)


Why not check for error_mark_node right after the tsubst_template_args?

On Tue, Aug 2, 2016 at 10:06 AM, Patrick Palka <patrick@parcs.ath.cx> wrote:
> This patch fixes PR c++/72759.  The problem seems to be that when
> instantiating a variable template, we fail to propagate error_mark_node
> when its template arguments are erroneous, and we instead build a bogus
> TEMPLATE_ID_EXPR which later confuses check_initializer().  Does this
> look OK to commit after bootstrap + regtesting?
>
> gcc/cp/ChangeLog:
>
>         PR c++/72759
>         * pt.c (tsubst_qualified_id): Return error_mark_node if
>         template_args is error_mark_node.
>
> gcc/testsuite/ChangeLog:
>
>         PR c++/72759
>         * g++.dg/cpp1y/pr72759.C: New test.
> ---
>  gcc/cp/pt.c                          |  3 +++
>  gcc/testsuite/g++.dg/cpp1y/pr72759.C | 18 ++++++++++++++++++
>  2 files changed, 21 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr72759.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index a23a05a..6b70a65 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -13907,6 +13907,9 @@ tsubst_qualified_id (tree qualified_id, tree args,
>
>    if (is_template)
>      {
> +      if (template_args == error_mark_node)
> +       return error_mark_node;
> +
>        if (variable_template_p (expr))
>         expr = lookup_and_finish_template_variable (expr, template_args,
>                                                     complain);
> diff --git a/gcc/testsuite/g++.dg/cpp1y/pr72759.C b/gcc/testsuite/g++.dg/cpp1y/pr72759.C
> new file mode 100644
> index 0000000..4af6ea4
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/pr72759.C
> @@ -0,0 +1,18 @@
> +// PR c++/72759
> +// { dg-do compile { target c++14 } }
> +
> +template <typename> struct SpecPerType;
> +class Specializer {
> +  public:  template <bool> static void MbrFnTempl();
> +  template <unsigned> struct A { static void InnerMemberFn(); };
> +  void Trigger() { A<0>::InnerMemberFn; }
> +};
> +template <> struct SpecPerType<Specializer> {
> +  using FnType = void *;
> +  template <bool P>
> +  static constexpr FnType SpecMbrFnPtr = Specializer::MbrFnTempl<P>;
> +};
> +template <unsigned X> void Specializer::A<X>::InnerMemberFn() {
> +  using Spec = SpecPerType<Specializer>;
> +  Spec ErrorSite = Spec::SpecMbrFnPtr<SpecMbrFnPtr>;  // { dg-error "not declared" }
> +}
> --
> 2.9.2.564.g4d4f0b7
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]