Jason Merrill <ja...@redhat.com> writes:

> Let's check for PTRMEM_CST separately, before any of the other tests.

Like this?  I still need to run it through bootstrap ...

gcc/cp/

        PR c++/51476
        * pt.c (convert_nontype_argument): Don't call maybe_constant_value
        for PTRMEM_CST nodes.

gcc/testsuite/

        PR c++/51476
        * cpp0x/ptrmem-cst-arg1.C: New test.
---
 gcc/cp/pt.c                                  |   10 +++++++---
 gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C |    9 +++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bb5aa0c..d127a7b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5720,11 +5720,15 @@ convert_nontype_argument (tree type, tree expr, 
tsubst_flags_t complain)
      to a null value, but otherwise still need to be of a specific form.  */
   if (cxx_dialect >= cxx0x)
     {
-      if (INTEGRAL_OR_ENUMERATION_TYPE_P (type))
+      if (TREE_CODE (expr) == PTRMEM_CST)
+       /* We don't need to test if a PTRMEM_CST is a constant value
+          because maybe_constant_value might crash and because
+          [temp.arg.nontype]/1 says it's not allowed as a template
+          argument anyway.  */;
+      else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type))
        expr = maybe_constant_value (expr);
       else if (TYPE_PTR_P (type)
-              || (TYPE_PTR_TO_MEMBER_P (type)
-                  && TREE_CODE (expr) != PTRMEM_CST))
+              || TYPE_PTR_TO_MEMBER_P (type))
        {
          tree folded = maybe_constant_value (expr);
          if (TYPE_PTR_P (type) ? integer_zerop (folded)
diff --git a/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C 
b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C
new file mode 100644
index 0000000..b6c81d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C
@@ -0,0 +1,9 @@
+// Origin PR c++/51476
+// { dg-options "-std=c++11" }
+
+template<int> struct A {};                                                     
          
+struct B
+{
+    int i;
+    A<&B::i> a; // { dg-error "could not convert template argument" }
+};
-- 
1.7.6.4


-- 
                Dodji

Reply via email to