public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/80840, ICE with constexpr and reference template parm
Date: Wed, 31 May 2017 17:16:00 -0000	[thread overview]
Message-ID: <CADzB+2nPNqi2uCRQrAUcRKwz4=6PEqG1Jy9vObLOJj3b9pzMew@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 404 bytes --]

In convert_nontype_argument to reference type we were inappropriately
checking value_dependent_expression_p on an expression that might be a
VAR_DECL and might be a TEMPLATE_PARM_INDEX of reference type.  It's
inappropriate in the former case because we don't care about the value
of the object, only its address; we only want to test for the latter
case.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 80840.diff --]
[-- Type: text/plain, Size: 1700 bytes --]

commit 388ec8de844dda6785d55daef0fffc90eb49118c
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 30 21:38:17 2017 -0400

            PR c++/80840 - ICE with constexpr and reference
    
            * pt.c (convert_nontype_argument): Don't test whether a decl is
            value-dependent when binding to a reference.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c1a8885..8239a3e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6749,7 +6749,11 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	    }
 	}
 
-      if (!value_dependent_expression_p (expr))
+      if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
+	  && value_dependent_expression_p (expr))
+	/* OK, dependent reference.  We don't want to ask whether a DECL is
+	   itself value-dependent, since what we want here is its address.  */;
+      else
 	{
 	  if (!DECL_P (expr))
 	    {
@@ -6771,8 +6775,11 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	      return NULL_TREE;
 	    }
 
-	  expr = build_nop (type, build_address (expr));
+	  expr = build_address (expr);
 	}
+
+      if (!same_type_p (type, TREE_TYPE (expr)))
+	expr = build_nop (type, expr);
     }
   /* [temp.arg.nontype]/5, bullet 4
 
diff --git a/gcc/testsuite/g++.dg/template/ref10.C b/gcc/testsuite/g++.dg/template/ref10.C
new file mode 100644
index 0000000..60e91d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ref10.C
@@ -0,0 +1,13 @@
+// PR c++/80840
+// { dg-do compile { target c++11 } }
+
+template <class T, T X>
+struct Just;
+
+template <const double& X>
+struct Number {
+    static constexpr double value = X;
+    using result = Just<const double&, value>;
+};
+
+int main() {}

                 reply	other threads:[~2017-05-31 17:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADzB+2nPNqi2uCRQrAUcRKwz4=6PEqG1Jy9vObLOJj3b9pzMew@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).