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

2016-08-03 Thread Jason Merrill
OK.

On Wed, Aug 3, 2016 at 8:02 PM, Patrick Palka  wrote:
> On Wed, 3 Aug 2016, Jason Merrill wrote:
>
>> Why not check for error_mark_node right after the tsubst_template_args?
>
> No good reason.  This seems to work too.  Does the following look OK
> after bootstrap + regtest?
>
> -- >8 --
>
> 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  |  2 ++
>  gcc/testsuite/g++.dg/cpp1y/pr72759.C | 18 ++
>  2 files changed, 20 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..7663916 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -13826,6 +13826,8 @@ tsubst_qualified_id (tree qualified_id, tree args,
>if (template_args)
> template_args = tsubst_template_args (template_args, args,
>   complain, in_decl);
> +  if (template_args == error_mark_node)
> +   return error_mark_node;
>name = TREE_OPERAND (name, 0);
>  }
>else
> diff --git a/gcc/testsuite/g++.dg/cpp1y/pr72759.C 
> b/gcc/testsuite/g++.dg/cpp1y/pr72759.C
> new file mode 100644
> index 000..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  struct SpecPerType;
> +class Specializer {
> +  public:  template  static void MbrFnTempl();
> +  template  struct A { static void InnerMemberFn(); };
> +  void Trigger() { A<0>::InnerMemberFn; }
> +};
> +template <> struct SpecPerType {
> +  using FnType = void *;
> +  template 
> +  static constexpr FnType SpecMbrFnPtr = Specializer::MbrFnTempl;
> +};
> +template  void Specializer::A::InnerMemberFn() {
> +  using Spec = SpecPerType;
> +  Spec ErrorSite = Spec::SpecMbrFnPtr;  // { dg-error "not 
> declared" }
> +}
> --
> 2.9.2.564.g4d4f0b7
>


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

2016-08-03 Thread Patrick Palka
On Wed, 3 Aug 2016, Jason Merrill wrote:

> Why not check for error_mark_node right after the tsubst_template_args?

No good reason.  This seems to work too.  Does the following look OK
after bootstrap + regtest?

-- >8 -- 

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  |  2 ++
 gcc/testsuite/g++.dg/cpp1y/pr72759.C | 18 ++
 2 files changed, 20 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..7663916 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13826,6 +13826,8 @@ tsubst_qualified_id (tree qualified_id, tree args,
   if (template_args)
template_args = tsubst_template_args (template_args, args,
  complain, in_decl);
+  if (template_args == error_mark_node)
+   return error_mark_node;
   name = TREE_OPERAND (name, 0);
 }
   else
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr72759.C 
b/gcc/testsuite/g++.dg/cpp1y/pr72759.C
new file mode 100644
index 000..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  struct SpecPerType;
+class Specializer {
+  public:  template  static void MbrFnTempl();
+  template  struct A { static void InnerMemberFn(); };
+  void Trigger() { A<0>::InnerMemberFn; }
+};
+template <> struct SpecPerType {
+  using FnType = void *;
+  template 
+  static constexpr FnType SpecMbrFnPtr = Specializer::MbrFnTempl;
+};
+template  void Specializer::A::InnerMemberFn() {
+  using Spec = SpecPerType;
+  Spec ErrorSite = Spec::SpecMbrFnPtr;  // { dg-error "not 
declared" }
+}
-- 
2.9.2.564.g4d4f0b7



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

2016-08-03 Thread Jason Merrill
Why not check for error_mark_node right after the tsubst_template_args?

On Tue, Aug 2, 2016 at 10:06 AM, Patrick Palka  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 000..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  struct SpecPerType;
> +class Specializer {
> +  public:  template  static void MbrFnTempl();
> +  template  struct A { static void InnerMemberFn(); };
> +  void Trigger() { A<0>::InnerMemberFn; }
> +};
> +template <> struct SpecPerType {
> +  using FnType = void *;
> +  template 
> +  static constexpr FnType SpecMbrFnPtr = Specializer::MbrFnTempl;
> +};
> +template  void Specializer::A::InnerMemberFn() {
> +  using Spec = SpecPerType;
> +  Spec ErrorSite = Spec::SpecMbrFnPtr;  // { dg-error "not 
> declared" }
> +}
> --
> 2.9.2.564.g4d4f0b7
>


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

2016-08-02 Thread Patrick Palka
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 000..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  struct SpecPerType;
+class Specializer {
+  public:  template  static void MbrFnTempl();
+  template  struct A { static void InnerMemberFn(); };
+  void Trigger() { A<0>::InnerMemberFn; }
+};
+template <> struct SpecPerType {
+  using FnType = void *;
+  template 
+  static constexpr FnType SpecMbrFnPtr = Specializer::MbrFnTempl;
+};
+template  void Specializer::A::InnerMemberFn() {
+  using Spec = SpecPerType;
+  Spec ErrorSite = Spec::SpecMbrFnPtr;  // { dg-error "not 
declared" }
+}
-- 
2.9.2.564.g4d4f0b7