From: Jason Merrill Date: Wed, 5 Aug 2015 17:51:29 +0000 (-0400) Subject: re PR c++/65195 (Variable template cannot be used as a function) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=85171e7877e60e2af5a76b0961e3ee8903bd084f;p=gcc.git re PR c++/65195 (Variable template cannot be used as a function) PR c++/65195 PR c++/66619 * semantics.c (finish_id_expression): Call convert_from_reference for variable template. From-SVN: r226641 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f51132cf852..382ad9a8a4b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2015-08-05 Jason Merrill + + PR c++/65195 + PR c++/66619 + * semantics.c (finish_id_expression): Call convert_from_reference + for variable template. + 2015-08-04 Jason Merrill * pt.c (lookup_template_class_1): Clear elt.spec. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 44f9f7acaa3..d42838e78cc 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3564,6 +3564,7 @@ finish_id_expression (tree id_expression, { decl = finish_template_variable (decl); mark_used (decl); + decl = convert_from_reference (decl); } else if (scope) { diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ37.C b/gcc/testsuite/g++.dg/cpp1y/var-templ37.C new file mode 100644 index 00000000000..11021a3f5bc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ37.C @@ -0,0 +1,23 @@ +// PR c++/65195 +// { dg-do compile { target c++14 } } + +template +T constant {}; + +template +struct foo { + int operator()() const + { return 3; } +}; + +template +auto& f = constant>; + +int main() +{ + // fine + auto& ref = f; ref(); + + // error: f cannot be used as a function + f(); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ40.C b/gcc/testsuite/g++.dg/cpp1y/var-templ40.C new file mode 100644 index 00000000000..0a952c48061 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ40.C @@ -0,0 +1,9 @@ +// PR c++/66619 +// { dg-do compile { target c++14 } } + +int y; +template T val1 = y; +auto&& x1 = val1; + +template T val2 = 0; +auto&& x2 = val2;