From d04a575f62b621e3df75c2cd7823a6613a2f1dc8 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 7 Oct 2003 07:07:07 +0000 Subject: [PATCH] re PR c++/10147 (Confusing error message for invalid template function argument) PR c++/10147 * call.c (initialize_reference): Tweak error message. PR c++/12337 * init.c (build_new_1): Make sure that the expression returned is not an lvalue. PR c++/12344, c++/12236, c++/8656 * decl.c (start_function): Do not ignore attributes embedded in a function declarator. PR c++/12337 * g++.dg/init/new9.C: New test. PR c++/12334, c++/12236, c++/8656 * g++.dg/ext/attrib8.C: New test. From-SVN: r72183 --- gcc/cp/ChangeLog | 17 +++++++++++++++++ gcc/cp/call.c | 4 +++- gcc/cp/cxx-pretty-print.c | 4 +--- gcc/cp/cxx-pretty-print.h | 4 +--- gcc/cp/decl.c | 2 +- gcc/cp/init.c | 8 +++++++- gcc/testsuite/ChangeLog | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/attrib8.C | 9 +++++++++ gcc/testsuite/g++.dg/init/new9.C | 22 ++++++++++++++++++++++ gcc/testsuite/g++.dg/other/error4.C | 2 +- gcc/testsuite/g++.dg/template/ptrmem4.C | 2 +- 11 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib8.C create mode 100644 gcc/testsuite/g++.dg/init/new9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2895c0e..3cbb85c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,22 @@ 2003-10-06 Mark Mitchell + PR c++/10147 + * call.c (initialize_reference): Tweak error message. + * cxx-pretty-print.h (cxx_pretty_printer_flags): Remove + pp_cxx_flag_qualified_id and pp_cxx_flag_global_scope. + * cxx-pretty-print.c (pp_cxx_id_expression): Always display + qualified entities using qualified names. + + PR c++/12337 + * init.c (build_new_1): Make sure that the expression returned is + not an lvalue. + + PR c++/12344, c++/12236, c++/8656 + * decl.c (start_function): Do not ignore attributes embedded in a + function declarator. + +2003-10-06 Mark Mitchell + * Make-lang.in (c++.info): Remove. (c++.dvi): Remove. (c++.generated-manpages): Replace with ... diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 989a84a..a8dcd2a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6055,7 +6055,9 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup) "type '%T' from a temporary of type '%T'", type, TREE_TYPE (expr)); else - error ("could not convert `%E' to `%T'", expr, type); + error ("invalid initialization of reference of type " + "'%T' from expression of type '%T'", type, + TREE_TYPE (expr)); return error_mark_node; } diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 69ee6b5..834cf88 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -268,9 +268,7 @@ pp_cxx_id_expression (cxx_pretty_printer *pp, tree t) { if (TREE_CODE (t) == OVERLOAD) t = OVL_CURRENT (t); - if ((TREE_CODE (t) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (t)) - || (pp_c_base (pp)->flags - & (pp_cxx_flag_qualified_id | pp_cxx_flag_global_scope))) + if (DECL_P (t) && DECL_CONTEXT (t)) pp_cxx_qualified_id (pp, t); else pp_cxx_unqualified_id (pp, t); diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h index d75c282..b47eff0 100644 --- a/gcc/cp/cxx-pretty-print.h +++ b/gcc/cp/cxx-pretty-print.h @@ -30,9 +30,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA typedef enum { /* Ask for an qualified-id. */ - pp_cxx_flag_qualified_id = 1 << pp_c_flag_last_bit, - pp_cxx_flag_global_scope = 1 << (pp_c_flag_last_bit + 1), - pp_cxx_flag_default_argument = 1 << (pp_c_flag_last_bit + 2) + pp_cxx_flag_default_argument = 1 << pp_c_flag_last_bit } cxx_pretty_printer_flags; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 729e549..4b23ee2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13135,7 +13135,7 @@ start_function (tree declspecs, tree declarator, tree attrs, int flags) } else { - decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL); + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs); /* If the declarator is not suitable for a function definition, cause a syntax error. */ if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) diff --git a/gcc/cp/init.c b/gcc/cp/init.c index fefda4b..5030345 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2276,7 +2276,13 @@ build_new_1 (tree exp) } /* Convert to the final type. */ - return build_nop (pointer_type, rval); + rval = build_nop (pointer_type, rval); + + /* A new-expression is never an lvalue. */ + if (real_lvalue_p (rval)) + rval = build1 (NON_LVALUE_EXPR, TREE_TYPE (rval), rval); + + return rval; } static tree diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c87236..21f4e15 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2003-10-06 Mark Mitchell + + PR c++/10147 + * g++.dg/other/error4.C: Update error messages. + * g++.dg/template/ptrmem4.C: Likewise. + + PR c++/12337 + * g++.dg/init/new9.C: New test. + + PR c++/12334, c++/12236, c++/8656 + * g++.dg/ext/attrib8.C: New test. + 2003-10-06 Devang Patel * gcc.dg/debug/dwarf2-3.h: New test. diff --git a/gcc/testsuite/g++.dg/ext/attrib8.C b/gcc/testsuite/g++.dg/ext/attrib8.C new file mode 100644 index 0000000..12f6d0b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib8.C @@ -0,0 +1,9 @@ +// PR 8656 + +extern int * (__attribute__((stdcall)) *fooPtr)( void); +int * __attribute__((stdcall)) myFn01( void) { return 0; } + +void snafu( void) +{ + fooPtr = myFn01; +} diff --git a/gcc/testsuite/g++.dg/init/new9.C b/gcc/testsuite/g++.dg/init/new9.C new file mode 100644 index 0000000..6729d76 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new9.C @@ -0,0 +1,22 @@ +// PR 12337 + +class A {}; + +template +class X : public A { +public: + X(T&); +}; + +class B { +public: + bool foo(A*); + template + bool foo(T& t) { return foo(new X(t)); } +}; + +int main() +{ + B x, y; + x.foo(y); +} diff --git a/gcc/testsuite/g++.dg/other/error4.C b/gcc/testsuite/g++.dg/other/error4.C index 39a612b..bd740d9 100644 --- a/gcc/testsuite/g++.dg/other/error4.C +++ b/gcc/testsuite/g++.dg/other/error4.C @@ -11,5 +11,5 @@ void Foo(int const &); // { dg-error "in passing" "" } void Baz () { - Foo (Wrapper ()); // { dg-error "convert `Wrapper *\\(\\)' to" "" } + Foo (Wrapper ()); // { dg-error "Wrapper" "" } } diff --git a/gcc/testsuite/g++.dg/template/ptrmem4.C b/gcc/testsuite/g++.dg/template/ptrmem4.C index 2310728..5cfd8c7 100644 --- a/gcc/testsuite/g++.dg/template/ptrmem4.C +++ b/gcc/testsuite/g++.dg/template/ptrmem4.C @@ -16,5 +16,5 @@ struct SpyExample void SpyExample::ready() { - queryAliases(inputs); // { dg-error "convert" } + queryAliases(inputs); // { dg-error "" } } -- 2.7.4