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++/84489, dependent default template argument
Date: Tue, 27 Feb 2018 17:26:00 -0000	[thread overview]
Message-ID: <CADzB+2m=LGcK+OOCKMXu3MSU8zbq0-15xiJ91TsNqhx=pUTcrQ@mail.gmail.com> (raw)

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

The logic in type_unification_real for handling template parms that
depend on earlier template parms is a bit complicated.  It already
recognizes when the type of the parm depends on something not
available yet, and it dealt with the case where substituting partial
args left some template parm uses behind, but it didn't handle the
case where substituting partial args just failed.

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

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

commit dade5ae09222e696b2aaa05d730e2414b3568bd4
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Feb 26 23:38:10 2018 -0500

            PR c++/84489 - dependent default template argument
    
            * pt.c (type_unification_real): Handle early substitution failure.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 40c897aadc9..2a64fa6d9ad 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19831,21 +19831,28 @@ type_unification_real (tree tparms,
 	    continue;
 	  tree parm = TREE_VALUE (tparm);
 
-	  if (TREE_CODE (parm) == PARM_DECL
-	      && uses_template_parms (TREE_TYPE (parm))
-	      && saw_undeduced < 2)
-	    continue;
+	  tsubst_flags_t fcomplain = complain;
+	  if (saw_undeduced == 1)
+	    {
+	      /* When saw_undeduced == 1, substitution into parm and arg might
+		 fail or not replace all template parameters, and that's
+		 fine.  */
+	      fcomplain = tf_none;
+	      if (TREE_CODE (parm) == PARM_DECL
+		  && uses_template_parms (TREE_TYPE (parm)))
+		continue;
+	    }
 
 	  tree arg = TREE_PURPOSE (tparm);
 	  reopen_deferring_access_checks (*checks);
 	  location_t save_loc = input_location;
 	  if (DECL_P (parm))
 	    input_location = DECL_SOURCE_LOCATION (parm);
-	  arg = tsubst_template_arg (arg, full_targs, complain, NULL_TREE);
-	  if (!uses_template_parms (arg))
+	  arg = tsubst_template_arg (arg, full_targs, fcomplain, NULL_TREE);
+	  if (arg != error_mark_node && !uses_template_parms (arg))
 	    arg = convert_template_argument (parm, arg, full_targs, complain,
 					     i, NULL_TREE);
-	  else if (saw_undeduced < 2)
+	  else if (saw_undeduced == 1)
 	    arg = NULL_TREE;
 	  else
 	    arg = error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
new file mode 100644
index 00000000000..636bf1afd88
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
@@ -0,0 +1,10 @@
+// PR c++/84489
+// { dg-do compile { target c++11 } }
+
+template <class T = int, T N = T(), bool B = (N >> 1)>
+T f1() {return 0;}
+
+int main()
+{
+  f1(); // Bug here
+}

             reply	other threads:[~2018-02-27 17:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 17:26 Jason Merrill [this message]
2018-03-23 22:14 ` Jason Merrill

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+2m=LGcK+OOCKMXu3MSU8zbq0-15xiJ91TsNqhx=pUTcrQ@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).