PR c++/69379
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Jan 2016 16:46:40 +0000 (16:46 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Jan 2016 16:46:40 +0000 (16:46 +0000)
* constexpr.c (cxx_eval_constant_expression): Handle PTRMEM_CSTs
wrapped in NOP_EXPRs.

* g++.dg/pr69379.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232882 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr69379.C [new file with mode: 0644]

index 6aa2176..c8653c4 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/69379
+       * constexpr.c (cxx_eval_constant_expression): Handle PTRMEM_CSTs
+       wrapped in NOP_EXPRs.
+
 2016-01-27  Martin Sebor  <msebor@redhat.com>
 
        PR c++/69317
index fd80000..57595a4 100644 (file)
@@ -3659,6 +3659,20 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
        if (TREE_CODE (op) == PTRMEM_CST
            && !TYPE_PTRMEM_P (type))
          op = cplus_expand_constant (op);
+       if (TREE_CODE (op) == PTRMEM_CST && tcode == NOP_EXPR)
+         {
+           if (same_type_ignoring_top_level_qualifiers_p (type,
+                                                          TREE_TYPE (op)))
+             STRIP_NOPS (t);
+           else
+             {
+               if (!ctx->quiet)
+                 error_at (EXPR_LOC_OR_LOC (t, input_location),
+                           "a reinterpret_cast is not a constant-expression");
+               *non_constant_p = true;
+               return t;
+             }
+         }
        if (POINTER_TYPE_P (type)
            && TREE_CODE (op) == INTEGER_CST
            && !integer_zerop (op))
index ad97714..40aa9c3 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/69379
+       * g++.dg/pr69379.C: New test.
+
 2016-01-27  Martin Sebor  <msebor@redhat.com>
 
        PR c++/69317
diff --git a/gcc/testsuite/g++.dg/pr69379.C b/gcc/testsuite/g++.dg/pr69379.C
new file mode 100644 (file)
index 0000000..249ad00
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/69379
+// { dg-do compile }
+// { dg-options "-Wformat" }
+
+typedef int T;
+class A {
+public:
+  template <class D> A(const char *, D);
+  template <class Fn, class A1, class A2>
+  void m_fn1(const char *, Fn, A1 const &, A2);
+};
+struct Dict {
+  void m_fn2();
+};
+void fn1() {
+  A a("", "");
+  typedef void *Get;
+  typedef void (Dict::*d)(T);
+  a.m_fn1("", Get(), d(&Dict::m_fn2), "");
+}