Index: testsuite/g++.dg/parse/template26.C =================================================================== --- testsuite/g++.dg/parse/template26.C (revision 0) +++ testsuite/g++.dg/parse/template26.C (revision 0) @@ -0,0 +1,18 @@ +// PR c++/50864 + +namespace impl +{ + template T create(); +} + +template ()->*impl::create())> +struct foo1; + +template ()->impl::create())> // { dg-error "not a class member" } +struct foo2; + +template ().impl::create())> // { dg-error "not a class member" } +struct foo3; Index: cp/parser.c =================================================================== --- cp/parser.c (revision 181133) +++ cp/parser.c (working copy) @@ -5969,10 +5969,19 @@ cp_parser_postfix_dot_deref_expression (cp_parser { if (name != error_mark_node && !BASELINK_P (name) && parser->scope) { - name = build_qualified_name (/*type=*/NULL_TREE, - parser->scope, - name, - template_p); + if (TREE_CODE (parser->scope) == NAMESPACE_DECL + && (TREE_CODE (postfix_expression) == ARROW_EXPR + || TREE_CODE (postfix_expression) == CALL_EXPR)) + { + error_at (token->location, "%<%D::%D%> is not a class member", + parser->scope, name); + postfix_expression = error_mark_node; + } + else + name = build_qualified_name (/*type=*/NULL_TREE, + parser->scope, + name, + template_p); parser->scope = NULL_TREE; parser->qualifying_scope = NULL_TREE; parser->object_scope = NULL_TREE;