diff options
author | Jason Merrill <jason@redhat.com> | 2017-06-28 15:41:18 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-06-28 15:41:18 -0400 |
commit | 2a4754f59786550a11706d807753c1747968ed01 (patch) | |
tree | e24e00fb3e20feec734eee2e34b6e2a3fbd24d52 | |
parent | ad669a1af4009b2d1f667716874758d91282869b (diff) | |
download | gcc-2a4754f59786550a11706d807753c1747968ed01.zip gcc-2a4754f59786550a11706d807753c1747968ed01.tar.gz gcc-2a4754f59786550a11706d807753c1747968ed01.tar.bz2 |
PR c++/81204 - parse error with dependent template-name
* parser.c (cp_parser_lookup_name): Disqualify function templates
after lookup.
From-SVN: r249750
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/lookup10.C | 12 |
3 files changed, 34 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b5c09ac..23586d4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-06-28 Jason Merrill <jason@redhat.com> + + PR c++/81204 - parse error with dependent template-name + * parser.c (cp_parser_lookup_name): Disqualify function templates + after lookup. + 2017-06-27 Nathan Sidwell <nathan@acm.org> * pt.c (tsubst_decl <FUNCTION_DECL>): Move var decls to diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2ff6afd..e0a6c8b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -25813,11 +25813,22 @@ cp_parser_lookup_name (cp_parser *parser, tree name, decl = NULL_TREE; if (!decl) - /* Look it up in the enclosing context. DR 141: When looking for a - template-name after -> or ., only consider class templates. */ - decl = lookup_name_real (name, prefer_type_arg (tag_type, is_template), - /*nonclass=*/0, - /*block_p=*/true, is_namespace, 0); + { + /* Look it up in the enclosing context. */ + decl = lookup_name_real (name, prefer_type_arg (tag_type), + /*nonclass=*/0, + /*block_p=*/true, is_namespace, 0); + /* DR 141 says when looking for a template-name after -> or ., only + consider class templates. */ + if (decl && is_template && !DECL_TYPE_TEMPLATE_P (decl)) + { + tree d = decl; + if (is_overloaded_fn (d)) + d = get_first_fn (d); + if (DECL_P (d) && !DECL_CLASS_SCOPE_P (d)) + decl = NULL_TREE; + } + } 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. */ diff --git a/gcc/testsuite/g++.dg/template/lookup10.C b/gcc/testsuite/g++.dg/template/lookup10.C new file mode 100644 index 0000000..fa90af4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/lookup10.C @@ -0,0 +1,12 @@ +// PR c++/81204 + +namespace std { + template<typename, typename> struct set { }; +} +using namespace std; + +template <int I, typename Result> +inline void set(Result & res) +{ + res.template set<I>(); +} |