[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-10-28 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #17 from Marek Polacek  ---
Should be fixed now.  Sorry it took so long.

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-10-28 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #16 from CVS Commits  ---
The master branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:323dd4255203479d8c456b85513db4f8e0041d04

commit r11-4499-g323dd4255203479d8c456b85513db4f8e0041d04
Author: Marek Polacek 
Date:   Mon Oct 19 18:13:42 2020 -0400

c++: Member template function lookup failure [PR94799]

My earlier patch for this PR, r11-86, broke pybind11.  That patch
changed cp_parser_class_name to also consider the object expression
scope (parser->context->object_type) to fix parsing of

  p->template A::foo(); // consider p's scope too

Here we reject

  b.operator typename B::type();

because 'typename_p' in cp_parser_class_name uses 'scope', which means
that 'typename_p' will be true for the example above.  Then we create
a TYPENAME_TYPE via make_typename_type, which fails when tsubsting it;
the code basically created 'typename B::B' and then we complain that there
is no member named 'B' in 'A'.  So, when deciding if we should
create a TYPENAME_TYPE, don't consider the object_type scope, like we
did pre-r11-86.

gcc/cp/ChangeLog:

PR c++/94799
* parser.c (cp_parser_class_name): Use parser->scope when
setting typename_p.

gcc/testsuite/ChangeLog:

PR c++/94799
* g++.dg/template/lookup16.C: New test.

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-10-24 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Marek Polacek  changed:

   What|Removed |Added

 CC||mar...@mpa-garching.mpg.de

--- Comment #15 from Marek Polacek  ---
*** Bug 97564 has been marked as a duplicate of this bug. ***

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-10-19 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #14 from Marek Polacek  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556517.html

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-10-19 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #13 from Marek Polacek  ---
The fix may be as easy as this:

--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -23812,8 +23812,8 @@ cp_parser_class_name (cp_parser *parser,

   /* Any name names a type if we're following the `typename' keyword
  in a qualified name where the enclosing scope is type-dependent.  */
-  typename_p = (typename_keyword_p && scope && TYPE_P (scope)
-   && dependent_type_p (scope));
+  typename_p = (typename_keyword_p && parser->scope && TYPE_P (parser->scope)
+   && dependent_type_p (parser->scope));
   /* Handle the common case (an identifier, but not a template-id)
  efficiently.  */
   if (token->type == CPP_NAME

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-08-17 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #12 from Marek Polacek  ---
(In reply to Volker Reichelt from comment #11)
> Hi Marek, any news on this one? It's three months now...
> Or should I file a new bug for the regression on trunk?

No news yet.  I've been largely away from upstream GCC for the past two months,
but I should have more time now.  I hope this will be fixed within the next
couple of weeks.  Sorry it's taking so long.

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-08-17 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #11 from Volker Reichelt  ---
Hi Marek, any news on this one? It's three months now...
Or should I file a new bug for the regression on trunk?

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-05-15 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #10 from Marek Polacek  ---
I see :(.  I'll take a look, thanks for noticing.

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-05-15 Thread reichelt at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Volker Reichelt  changed:

   What|Removed |Added

 CC||reichelt at gcc dot gnu.org

--- Comment #9 from Volker Reichelt  ---
Hi Marek,

your fix unfortunately breaks the following valid code (reduced from pybind11):

===
template  struct A
{
  typedef int type;
  operator int();
};

template  using B = A;

template  typename B::type foo(B b)
{
  return b.operator typename B::type();
}

void bar()
{
  foo(A());
}
===

bug.cc: In instantiation of 'typename B::type foo(B) [with T = int;
typename B::type = int; B = A; B = A]':
bug.cc:16:15:   required from here
bug.cc:11:36: error: no type named 'B' in 'struct A'
   11 |   return b.operator typename B::type();
  |  ~~^~~~

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-05-05 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Marek Polacek  changed:

   What|Removed |Added

Summary|[8/9/10/11 Regression]  |[8/9/10 Regression] Calling
   |Calling a member template   |a member template function
   |function fails  |fails

--- Comment #8 from Marek Polacek  ---
Fixed on trunk so far.  I plan to backport it to 10.2, maybe 9 too.

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-04-28 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Marek Polacek  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #6 from Marek Polacek  ---
https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544806.html

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-04-28 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Marek Polacek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

--- Comment #5 from Marek Polacek  ---
Finally I have something that seems to work...

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-04-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #4 from Marek Polacek  ---
Another test, where the name after . isn't an injected-class-name:

template struct B {
  void foo ();
  int i;
};

template
struct D : public B { };

template
void fn (D d)
{
  d.template B::foo ();
  d.template B::i = 42;
}

[Bug c++/94799] [8/9/10 Regression] Calling a member template function fails

2020-04-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

--- Comment #3 from Marek Polacek  ---
Here we have "p->template A::a()" but cp_parser_expression only parses the
"p->template A" part, so we complain that a ; isn't following.

It's because cp_parser_template_name now considers the object scope:

16957   if (template_keyword_p)
16958 {
16959   tree scope = (parser->scope ? parser->scope
16960 : parser->context->object_type);
16961   if (scope && TYPE_P (scope)
16962   && (!CLASS_TYPE_P (scope) 
16963   || (check_dependency_p && dependent_type_p (scope
16964 {
16965   /* We're optimizing away the call to cp_parser_lookup_name,
but
16966  we still need to do this.  */
16967   parser->context->object_type = NULL_TREE;
16968   return identifier;
16969 }
16970 }

which here is unknown_type_node, signalling a type-dependent object:

 7756   if (dependent_p)
 7757 /* Tell cp_parser_lookup_name that there was an object, even though
it's
 7758type-dependent.  */
 7759 parser->context->object_type = unknown_type_node;

so now cp_parser_template_name returns identifier 'A', cp_parser_class_name
creates a TEMPLATE_ID_EXPR A, but then

23735   decl = make_typename_type (scope, decl, tag_type, tf_error);

fails because scope is NULL -- we've used the object scope instead.  We
probably have to look that up first.