From: Jason Merrill Date: Wed, 15 Jul 2015 14:13:22 +0000 (-0400) Subject: re PR c++/65091 (decltype(~arg) fails for template functions) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0467e3ebef7688c50fb0141b10c8b5e7e4dbbcdf;p=gcc.git re PR c++/65091 (decltype(~arg) fails for template functions) PR c++/65091 * parser.c (cp_parser_unqualified_id): Don't accept ~x in a template if there is no type x in scope. From-SVN: r225831 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 00cbe47dfa4..6b92826118e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-07-15 Jason Merrill + + PR c++/65091 + * parser.c (cp_parser_unqualified_id): Don't accept ~x in a + template if there is no type x in scope. + 2015-07-14 Patrick Palka PR c++/66850 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 574ffba3ece..f1d5656055c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -5162,8 +5162,15 @@ cp_parser_unqualified_id (cp_parser* parser, if (processing_template_decl && ! cp_parser_parse_definitely (parser)) { - /* We couldn't find a type with this name, so just accept - it and check for a match at instantiation time. */ + /* We couldn't find a type with this name. If we're parsing + tentatively, fail and try something else. */ + if (cp_parser_uncommitted_to_tentative_parse_p (parser)) + { + cp_parser_simulate_error (parser); + return error_mark_node; + } + /* Otherwise, accept it and check for a match at instantiation + time. */ type_decl = cp_parser_identifier (parser); if (type_decl != error_mark_node) type_decl = build_nt (BIT_NOT_EXPR, type_decl); diff --git a/gcc/testsuite/g++.dg/parse/dtor17.C b/gcc/testsuite/g++.dg/parse/dtor17.C new file mode 100644 index 00000000000..1fca4132b87 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/dtor17.C @@ -0,0 +1,11 @@ +// PR c++/65091 +// { dg-do compile { target c++11 } } + +template +auto foo(T x) -> decltype(~x) { + return ~x; +} + +int bar() { + return foo(10); +}