public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to primary_template_instantiation_p
@ 2017-11-27 21:37 Jason Merrill
  2017-11-28 16:00 ` Maxim Kuvyrkov
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2017-11-27 21:37 UTC (permalink / raw)
  To: gcc-patches List

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

All the uses of primary_template_instantiation_p actually want to
query whether the entity in question is a specialization of the
template, not whether it's an instantiation or explicit
specialization.

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

[-- Attachment #2: primary-tmpl.diff --]
[-- Type: text/plain, Size: 5010 bytes --]

commit ca0a29985403027c3438e5c3c45af35ca1da6bb2
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Nov 17 12:18:57 2017 -0500

            * pt.c (primary_template_specialization_p): Rename from
    
            primary_template_instantiation_p.  Don't check
            DECL_TEMPLATE_INSTANTIATION.
            * call.c, cp-tree.h, decl2.c: Adjust.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d242b07a06b..177c3cc13e3 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3895,7 +3895,7 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
 		= bad_arg_conversion_rejection (NULL_TREE, -2,
 						rettype, totype);
 	    }
-	  else if (primary_template_instantiation_p (cand->fn)
+	  else if (primary_template_specialization_p (cand->fn)
 		   && ics->rank > cr_exact)
 	    {
 	      /* 13.3.3.1.2: If the user-defined conversion is specified by
@@ -6111,7 +6111,7 @@ aligned_deallocation_fn_p (tree t)
   /* A template instance is never a usual deallocation function,
      regardless of its signature.  */
   if (TREE_CODE (t) == TEMPLATE_DECL
-      || primary_template_instantiation_p (t))
+      || primary_template_specialization_p (t))
     return false;
 
   tree a = FUNCTION_ARG_CHAIN (t);
@@ -6136,7 +6136,7 @@ usual_deallocation_fn_p (tree t)
   /* A template instance is never a usual deallocation function,
      regardless of its signature.  */
   if (TREE_CODE (t) == TEMPLATE_DECL
-      || primary_template_instantiation_p (t))
+      || primary_template_specialization_p (t))
     return false;
 
   /* If a class T has a member deallocation function named operator delete
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1c19c3d31f8..cb12c835298 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6556,7 +6556,7 @@ extern void init_template_processing		(void);
 extern void print_template_statistics		(void);
 bool template_template_parameter_p		(const_tree);
 bool template_type_parameter_p                  (const_tree);
-extern bool primary_template_instantiation_p    (const_tree);
+extern bool primary_template_specialization_p   (const_tree);
 extern tree get_primary_template_innermost_parameters	(const_tree);
 extern tree get_template_parms_at_level (tree, int);
 extern tree get_template_innermost_arguments	(const_tree);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2b70969999e..53d86fb8722 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3219,7 +3219,7 @@ get_function_template_decl (const_tree primary_func_tmpl_inst)
 {
   if (! primary_func_tmpl_inst
       || TREE_CODE (primary_func_tmpl_inst) != FUNCTION_DECL
-      || ! primary_template_instantiation_p (primary_func_tmpl_inst))
+      || ! primary_template_specialization_p (primary_func_tmpl_inst))
     return NULL;
 
   return DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (primary_func_tmpl_inst));
@@ -3287,21 +3287,23 @@ make_ith_pack_parameter_name (tree name, int i)
 }
 
 /* Return true if T is a primary function, class or alias template
-   instantiation.  */
+   specialization, not including the template pattern.  */
 
 bool
-primary_template_instantiation_p (const_tree t)
+primary_template_specialization_p (const_tree t)
 {
   if (!t)
     return false;
 
-  if (TREE_CODE (t) == FUNCTION_DECL)
-    return DECL_LANG_SPECIFIC (t)
-	   && DECL_TEMPLATE_INSTANTIATION (t)
-	   && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t));
+  if (TREE_CODE (t) == FUNCTION_DECL || VAR_P (t))
+    return (DECL_LANG_SPECIFIC (t)
+	    && DECL_USE_TEMPLATE (t)
+	    && DECL_TEMPLATE_INFO (t)
+	    && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)));
   else if (CLASS_TYPE_P (t) && !TYPE_DECL_ALIAS_P (TYPE_NAME (t)))
-    return CLASSTYPE_TEMPLATE_INSTANTIATION (t)
-	   && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t));
+    return (CLASSTYPE_TEMPLATE_INFO (t)
+	    && CLASSTYPE_USE_TEMPLATE (t)
+	    && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
   else if (alias_template_specialization_p (t))
     return true;
   return false;
@@ -3336,7 +3338,7 @@ get_primary_template_innermost_parameters (const_tree t)
   tree parms = NULL, template_info = NULL;
 
   if ((template_info = get_template_info (t))
-      && primary_template_instantiation_p (t))
+      && primary_template_specialization_p (t))
     parms = INNERMOST_TEMPLATE_PARMS
 	(DECL_TEMPLATE_PARMS (TI_TEMPLATE (template_info)));
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C
new file mode 100644
index 00000000000..49c1e0557e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C
@@ -0,0 +1,27 @@
+// PR c++/46831
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct B { };
+struct D : B { };
+struct A {
+  template<typename T = void> operator D&(); // { dg-message "template conversion" }
+  operator long();
+};
+
+template <> A::operator D&();
+
+void f(long);
+void f(B&);
+
+struct A2 {
+  template<typename T = void> operator B&();
+};
+
+void f2(const B&);
+
+int main() {
+  f(A());
+  f2(A2());
+  f2(A());			// { dg-error "" }
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ PATCH to primary_template_instantiation_p
  2017-11-27 21:37 C++ PATCH to primary_template_instantiation_p Jason Merrill
@ 2017-11-28 16:00 ` Maxim Kuvyrkov
  2017-11-28 18:28   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Kuvyrkov @ 2017-11-28 16:00 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List


> On Nov 28, 2017, at 12:29 AM, Jason Merrill <jason@redhat.com> wrote:
> 
> All the uses of primary_template_instantiation_p actually want to
> query whether the entity in question is a specialization of the
> template, not whether it's an instantiation or explicit
> specialization.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.
> <primary-tmpl.diff>

Hi Jason,

I get the following failure with the new test on x86_64-linux-gnu and aarch64-linux-gnu:

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C
> @@ -0,0 +1,27 @@
> +// PR c++/46831
> +// { dg-do compile { target c++11 } }
> +// { dg-options "" }
> +
> +struct B { };
> +struct D : B { };
> +struct A {
> +  template<typename T = void> operator D&(); // { dg-message "template conversion" }
> +  operator long();
> +};
> +
> +template <> A::operator D&();

"Template conversion" warning is triggered on this line, rather than above.

> +
> +void f(long);
> +void f(B&);
> +
> +struct A2 {
> +  template<typename T = void> operator B&();
> +};
> +
> +void f2(const B&);
> +
> +int main() {
> +  f(A());
> +  f2(A2());
> +  f2(A());			// { dg-error "" }
> +}
> 

Would you please take a look?

===
spawn -ignore SIGHUP /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/gcc/testsuite/g++5/../../xg++ -B/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/gcc/testsuite/g++5/../../ /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C -fno-diagnostics-show-caret -fdiagnostics-color=never -nostdinc++ -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/x86_64-unknown-linux-gnu/libstdc++-v3/include -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/libsupc++ -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/include/backward -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/testsuite/util -fmessage-length=0 -std=gnu++11 -S -o fntmpdefarg2a.s
/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C: In function 'int main()':
/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:26:6: error: invalid user-defined conversion from 'A' to 'const B&' [-fpermissive]
/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:12:13: note: candidate is: 'A::operator D&() [with T = void]' <near match>
/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:12:13: note:   conversion from return type 'D&' of template conversion function specialization to 'const B&' is not an exact match
/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:21:6: note:   initializing argument 1 of 'void f2(const B&)'
compiler exited with status 1
FAIL: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11  (test for warnings, line 8)
PASS: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11  (test for errors, line 26)
PASS: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11 (test for excess errors)
===

Regards,

--
Maxim Kuvyrkov
www.linaro.org



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ PATCH to primary_template_instantiation_p
  2017-11-28 16:00 ` Maxim Kuvyrkov
@ 2017-11-28 18:28   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2017-11-28 18:28 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: gcc-patches List

Fixed, thanks.

On Tue, Nov 28, 2017 at 10:49 AM, Maxim Kuvyrkov
<maxim.kuvyrkov@linaro.org> wrote:
>
>> On Nov 28, 2017, at 12:29 AM, Jason Merrill <jason@redhat.com> wrote:
>>
>> All the uses of primary_template_instantiation_p actually want to
>> query whether the entity in question is a specialization of the
>> template, not whether it's an instantiation or explicit
>> specialization.
>>
>> Tested x86_64-pc-linux-gnu, applying to trunk.
>> <primary-tmpl.diff>
>
> Hi Jason,
>
> I get the following failure with the new test on x86_64-linux-gnu and aarch64-linux-gnu:
>
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C
>> @@ -0,0 +1,27 @@
>> +// PR c++/46831
>> +// { dg-do compile { target c++11 } }
>> +// { dg-options "" }
>> +
>> +struct B { };
>> +struct D : B { };
>> +struct A {
>> +  template<typename T = void> operator D&(); // { dg-message "template conversion" }
>> +  operator long();
>> +};
>> +
>> +template <> A::operator D&();
>
> "Template conversion" warning is triggered on this line, rather than above.
>
>> +
>> +void f(long);
>> +void f(B&);
>> +
>> +struct A2 {
>> +  template<typename T = void> operator B&();
>> +};
>> +
>> +void f2(const B&);
>> +
>> +int main() {
>> +  f(A());
>> +  f2(A2());
>> +  f2(A());                   // { dg-error "" }
>> +}
>>
>
> Would you please take a look?
>
> ===
> spawn -ignore SIGHUP /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/gcc/testsuite/g++5/../../xg++ -B/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/gcc/testsuite/g++5/../../ /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C -fno-diagnostics-show-caret -fdiagnostics-color=never -nostdinc++ -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/_build/builds/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/gcc.git~master-stage2/x86_64-unknown-linux-gnu/libstdc++-v3/include -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/libsupc++ -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/include/backward -I/home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/libstdc++-v3/testsuite/util -fmessage-length=0 -std=gnu++11 -S -o fntmpdefarg2a.s
> /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C: In function 'int main()':
> /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:26:6: error: invalid user-defined conversion from 'A' to 'const B&' [-fpermissive]
> /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:12:13: note: candidate is: 'A::operator D&() [with T = void]' <near match>
> /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:12:13: note:   conversion from return type 'D&' of template conversion function specialization to 'const B&' is not an exact match
> /home/tcwg-buildslave/workspace/tcwg-buildfarm/tcwg-x86_64-build/snapshots/gcc.git~master/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2a.C:21:6: note:   initializing argument 1 of 'void f2(const B&)'
> compiler exited with status 1
> FAIL: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11  (test for warnings, line 8)
> PASS: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11  (test for errors, line 26)
> PASS: g++.dg/cpp0x/fntmpdefarg2a.C  -std=gnu++11 (test for excess errors)
> ===
>
> Regards,
>
> --
> Maxim Kuvyrkov
> www.linaro.org
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-28 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 21:37 C++ PATCH to primary_template_instantiation_p Jason Merrill
2017-11-28 16:00 ` Maxim Kuvyrkov
2017-11-28 18:28   ` Jason Merrill

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).