+2020-05-05 Marek Polacek <polacek@redhat.com>
+ Jason Merrill <jason@redhat.com>
+
+ PR c++/94799
+ * parser.c (cp_parser_postfix_dot_deref_expression): If we have
+ a type-dependent object of class type, stash it to
+ parser->context->object_type. If the postfix expression doesn't have
+ a type, use typeof.
+ (cp_parser_class_name): Consider object scope too.
+ (cp_parser_lookup_name): Remove code dealing with the case when
+ object_type is unknown_type_node.
+
2020-05-04 Patrick Palka <ppalka@redhat.com>
PR c++/94038
}
if (dependent_p)
- /* Tell cp_parser_lookup_name that there was an object, even though it's
- type-dependent. */
- parser->context->object_type = unknown_type_node;
+ {
+ tree type = TREE_TYPE (postfix_expression);
+ /* If we don't have a (type-dependent) object of class type, use
+ typeof to figure out the type of the object. */
+ if (type == NULL_TREE)
+ type = finish_typeof (postfix_expression);
+ parser->context->object_type = type;
+ }
/* Assume this expression is not a pseudo-destructor access. */
pseudo_destructor_p = false;
}
/* PARSER->SCOPE can be cleared when parsing the template-arguments
- to a template-id, so we save it here. */
- scope = parser->scope;
+ to a template-id, so we save it here. Consider object scope too,
+ so that make_typename_type below can use it (cp_parser_template_name
+ considers object scope also). This may happen with code like
+
+ p->template A<T>::a()
+
+ where we first want to look up A<T>::a in the class of the object
+ expression, as per [basic.lookup.classref]. */
+ scope = parser->scope ? parser->scope : parser->context->object_type;
if (scope == error_mark_node)
return error_mark_node;
decl = lookup_name_real (name, prefer_type_arg (tag_type, is_template),
/*nonclass=*/0,
/*block_p=*/true, is_namespace, 0);
- if (object_type == unknown_type_node)
- /* The object is type-dependent, so we can't look anything up; we used
- this to get the DR 141 behavior. */
- object_type = NULL_TREE;
parser->object_scope = object_type;
parser->qualifying_scope = NULL_TREE;
}
+2020-05-05 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94799
+ * g++.dg/lookup/this1.C: Adjust dg-error.
+ * g++.dg/template/lookup12.C: New test.
+ * g++.dg/template/lookup13.C: New test.
+ * g++.dg/template/lookup14.C: New test.
+ * g++.dg/template/lookup15.C: New test.
+
2020-05-05 Martin Liska <mliska@suse.cz>
* gcc.dg/spellcheck-options-22.c: New test.
struct A
{
template<int> static void foo();
- static void bar() { this->A::foo<0>(); } // { dg-error "unavailable" }
+ static void bar() { this->A::foo<0>(); } // { dg-error "unavailable|not a class|expected" }
};
--- /dev/null
+// PR c++/94799 - member template function lookup fails.
+
+template<typename T> struct B {
+ void foo ();
+ int i;
+};
+
+template<typename T>
+struct D : public B<T> { };
+
+template<typename T>
+void fn (D<T> d)
+{
+ d.template B<T>::foo ();
+ d.template B<T>::i = 42;
+ D<T>().template B<T>::foo ();
+ d.template D<T>::template B<T>::foo ();
+ d.template D<T>::template B<T>::i = 10;
+}
+
+int
+main ()
+{
+ D<int> d;
+ fn(d);
+}
--- /dev/null
+// PR c++/94799 - member template function lookup fails.
+
+template <typename T>
+struct A {
+ int a() {
+ return 42;
+ }
+
+ template<typename> struct X { typedef int type; };
+};
+
+template <typename T>
+struct B {
+ int b(A<T> *p) {
+ int i = 0;
+ i += p->a();
+ i += p->template A<T>::a();
+ i += p->template A<T>::template A<T>::a();
+ i += A<T>().template A<T>::a();
+ return i;
+ }
+};
+
+int main() {
+ A<int> a;
+ B<int> b;
+ return b.b(&a);
+}
--- /dev/null
+// PR c++/94799 - member template function lookup fails.
+
+template<typename T>
+struct A { };
+
+template<typename T>
+void fn (A<T> a)
+{
+ // Don't perform name lookup of foo when parsing this template.
+ a.template A<T>::foo ();
+}
--- /dev/null
+// PR c++/94799 - member template function lookup fails.
+
+template<typename>
+struct M { void fn() { } };
+
+M<int>* bar (int);
+M<int> bar2 (int);
+
+template<typename T>
+struct X : M<T> {
+ void xfn ()
+ {
+ this->template M<T>::fn ();
+ bar((T)1)->template M<T>::fn ();
+ bar2((T)1).template M<T>::fn ();
+ }
+};
+
+int
+main ()
+{
+ X<int> x;
+ x.xfn();
+}