public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: dependent generic lambda template-id [PR106024]
@ 2022-07-01 14:51 Jason Merrill
  2022-07-06  4:39 ` [pushed] c++: dependent conversion operator lookup [PR106179] Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2022-07-01 14:51 UTC (permalink / raw)
  To: gcc-patches

We were wrongly looking up the generic lambda op() in a dependent scope, and
then trying to look up its instantiation at substitution time, but lambdas
aren't instantiated, so we crashed.  The fix is to not look into dependent
class scopes.

But this created trouble with wrongly trying to use a template from the
enclosing scope when we aren't actually looking at a template-argument-list,
in template/lookup18.C, so let's avoid that.

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

	PR c++/106024

gcc/cp/ChangeLog:

	* parser.cc (missing_template_diag): Factor out...
	(cp_parser_id_expression): ...from here.
	(cp_parser_lookup_name): Don't look in dependent object_type.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/lambda-generic10.C: New test.
---
 gcc/cp/parser.cc                              | 23 ++++++++++++++++++-
 gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C | 14 +++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index da2f370cdca..357fde557c7 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -30676,9 +30676,11 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
     }
   else if (object_type)
     {
+      bool dep = dependent_scope_p (object_type);
+
       /* Look up the name in the scope of the OBJECT_TYPE, unless the
 	 OBJECT_TYPE is not a class.  */
-      if (CLASS_TYPE_P (object_type))
+      if (!dep && CLASS_TYPE_P (object_type))
 	/* If the OBJECT_TYPE is a template specialization, it may
 	   be instantiated during name lookup.  In that case, errors
 	   may be issued.  Even if we rollback the current tentative
@@ -30702,6 +30704,25 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
 			    : is_template ? LOOK_want::TYPE
 			    : prefer_type_arg (tag_type));
 
+      /* If we did unqualified lookup of a dependent member-qualified name and
+	 found something, do we want to use it?  P1787 clarified that we need
+	 to look in the object scope first even if it's dependent, but for now
+	 let's still use it in some cases.
+	 FIXME remember unqualified lookup result to use if member lookup fails
+	 at instantiation time.	 */
+      if (decl && dep && is_template)
+	{
+	  saved_token_sentinel toks (parser->lexer, STS_ROLLBACK);
+	  /* Only use the unqualified class template lookup if we're actually
+	     looking at a template arg list.  */
+	  if (!cp_parser_skip_entire_template_parameter_list (parser))
+	    decl = NULL_TREE;
+	  /* And only use the unqualified lookup if we're looking at ::.  */
+	  if (decl
+	      && !cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
+	    decl = NULL_TREE;
+	}
+
       /* If we know we're looking for a type (e.g. A in p->A::x),
 	 mock up a typename.  */
       if (!decl && object_type && tag_type != none_type
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C
new file mode 100644
index 00000000000..47a87bbfbd7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C
@@ -0,0 +1,14 @@
+// PR c++/106024
+// { dg-do compile { target c++20 } }
+
+void sink(...);
+template <int... args> void f()
+{
+  sink ([] <int T> (int...) { return 1; }
+        .operator()<args>(args...)...); // { dg-warning "-Wmissing-template-keyword" }
+} // { dg-prune-output {expected '\)'} }
+
+int main()
+{
+  f<1,2,3>();
+}

base-commit: 63abe04999283582b258adf60da6c19d541ebc68
-- 
2.27.0


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

* [pushed] c++: dependent conversion operator lookup [PR106179]
  2022-07-01 14:51 [pushed] c++: dependent generic lambda template-id [PR106024] Jason Merrill
@ 2022-07-06  4:39 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-07-06  4:39 UTC (permalink / raw)
  To: gcc-patches

This testcase demonstrates that my assumption that we would only be
interested in a class template lookup if the template-id is followed by ::
was wrong.

	PR c++/106179
	PR c++/106024

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_lookup_name): Remove :: requirement
	for using unqualified lookup result.

gcc/testsuite/ChangeLog:

	* g++.dg/template/operator16.C: New test.
---
 gcc/cp/parser.cc                           | 4 ----
 gcc/testsuite/g++.dg/template/operator16.C | 9 +++++++++
 2 files changed, 9 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/operator16.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index df657a3fb2b..5cd6a527d93 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -30738,10 +30738,6 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
 	     looking at a template arg list.  */
 	  if (!cp_parser_skip_entire_template_parameter_list (parser))
 	    decl = NULL_TREE;
-	  /* And only use the unqualified lookup if we're looking at ::.  */
-	  if (decl
-	      && !cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
-	    decl = NULL_TREE;
 	}
 
       /* If we know we're looking for a type (e.g. A in p->A::x),
diff --git a/gcc/testsuite/g++.dg/template/operator16.C b/gcc/testsuite/g++.dg/template/operator16.C
new file mode 100644
index 00000000000..434a266850c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/operator16.C
@@ -0,0 +1,9 @@
+// PR c++/106179
+
+struct Mat {
+  template <typename> Mat();
+};
+template <typename> struct Mat_;
+template <typename _Tp> Mat::Mat() {
+  _Tp commaInitializer = commaInitializer.operator Mat_<_Tp>;
+}

base-commit: 510ac273a785361f7c8f24e4815bfb477a6a2e07
-- 
2.27.0


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

end of thread, other threads:[~2022-07-06  4:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 14:51 [pushed] c++: dependent generic lambda template-id [PR106024] Jason Merrill
2022-07-06  4:39 ` [pushed] c++: dependent conversion operator lookup [PR106179] 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).