From d5a10cf069a2f84e5b24a22e1eecc91918ea8875 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 7 Jun 2004 15:54:15 +0000 Subject: [PATCH] re PR c++/15337 (sizeof on incomplete type diagnostic) PR c++/15337 * error.c (c_sizeof_or_alignof_type): Use more detailed error message. PR c++/15766 * parser.c (cp_parser_iteration_statement): Fix typo in error message. PR c++/14777 * pt.c (tsubst_default_argument): Do not defer access checks while substituting into the default argument. PR c++/15554 * pt.c (tsubst_copy): Do not try to substitute for an enumeration constant in a non-dependent context. PR c++/15057 * except.c (build_throw): Ensure that temp_expr has been initialized. PR c++/15337 * g++.dg/expr/sizeof3.C: New test. PR c++/14777 * g++.dg/template/access14.C: New test. PR c++/15554 * g++.dg/template/enum1.C: New test. PR c++/15057 * g++.dg/eh/throw1.C: New test. From-SVN: r82693 --- gcc/ChangeLog | 6 ++++++ gcc/c-common.c | 3 ++- gcc/cp/ChangeLog | 18 ++++++++++++++++++ gcc/cp/except.c | 1 + gcc/cp/parser.c | 4 ++-- gcc/cp/pt.c | 15 +++++++-------- gcc/testsuite/ChangeLog | 14 ++++++++++++++ gcc/testsuite/g++.dg/eh/throw1.C | 9 +++++++++ gcc/testsuite/g++.dg/expr/sizeof3.C | 4 ++++ gcc/testsuite/g++.dg/template/access14.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/template/enum1.C | 5 +++++ 11 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/throw1.C create mode 100644 gcc/testsuite/g++.dg/expr/sizeof3.C create mode 100644 gcc/testsuite/g++.dg/template/access14.C create mode 100644 gcc/testsuite/g++.dg/template/enum1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 98dd0160724..200b595cdef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-06-07 Mark Mitchell + + PR c++/15337 + * error.c (c_sizeof_or_alignof_type): Use more detailed error + message. + 2004-06-06 Paolo Bonzini * config.in: Regenerate. diff --git a/gcc/c-common.c b/gcc/c-common.c index 4b2b35501f0..89bc80e9353 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -3060,7 +3060,8 @@ c_sizeof_or_alignof_type (tree type, enum tree_code op, int complain) else if (!COMPLETE_TYPE_P (type)) { if (complain) - error ("invalid application of `%s' to an incomplete type", op_name); + error ("invalid application of `%s' to incomplete type `%T' ", + op_name, type); value = size_zero_node; } else diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5bb506e58f5..6dfe64a1fde 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,21 @@ +2004-06-07 Mark Mitchell + + PR c++/15766 + * parser.c (cp_parser_iteration_statement): Fix typo in error + message. + + PR c++/14777 + * pt.c (tsubst_default_argument): Do not defer access checks + while substituting into the default argument. + + PR c++/15554 + * pt.c (tsubst_copy): Do not try to substitute for an enumeration + constant in a non-dependent context. + + PR c++/15057 + * except.c (build_throw): Ensure that temp_expr has been + initialized. + 2004-06-06 Roger Sayle * cp/cp-tree.h (lvalue_or_else): Add function prototype. diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 79f1dfac0d9..69813d3ac7b 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -684,6 +684,7 @@ build_throw (tree exp) because it will only return false in cases where elided is true, and therefore we don't need to work around the failure to preevaluate. */ + temp_expr = NULL_TREE; stabilize_init (exp, &temp_expr); if (elided) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0c94f7102db..d094d306ee8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6138,8 +6138,8 @@ cp_parser_iteration_statement (cp_parser* parser) expression = cp_parser_expression (parser); finish_for_expr (expression, statement); /* Look for the `)'. */ - cp_parser_require (parser, CPP_CLOSE_PAREN, "`;'"); - + cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"); + /* Parse the body of the for-statement. */ parser->in_iteration_statement_p = true; cp_parser_already_scoped_statement (parser); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7d915dc7390..8e29e244f71 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5895,22 +5895,18 @@ tsubst_default_argument (tree fn, tree type, tree arg) }; we must be careful to do name lookup in the scope of S, - rather than in the current class. - - ??? current_class_type affects a lot more than name lookup. This is - very fragile. Fortunately, it will go away when we do 2-phase name - binding properly. */ - - /* FN is already the desired FUNCTION_DECL. */ + rather than in the current class. */ push_access_scope (fn); /* The default argument expression should not be considered to be within the scope of FN. Since push_access_scope sets current_function_decl, we must explicitly clear it here. */ current_function_decl = NULL_TREE; + push_deferring_access_checks(dk_no_deferred); arg = tsubst_expr (arg, DECL_TI_ARGS (fn), tf_error | tf_warning, NULL_TREE); - + pop_deferring_access_checks(); + pop_access_scope (fn); /* Make sure the default argument is reasonable. */ @@ -7423,6 +7419,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) enumerators. */ if (DECL_NAMESPACE_SCOPE_P (t)) return t; + /* If ARGS is NULL, then T is known to be non-dependent. */ + if (args == NULL_TREE) + return t; /* Unfortunately, we cannot just call lookup_name here. Consider: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index af96cb7c567..3ffd9c264cb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2004-06-07 Mark Mitchell + + PR c++/15337 + * g++.dg/expr/sizeof3.C: New test. + + PR c++/14777 + * g++.dg/template/access14.C: New test. + + PR c++/15554 + * g++.dg/template/enum1.C: New test. + + PR c++/15057 + * g++.dg/eh/throw1.C: New test. + 2004-06-07 David Ayers Ziemowit Laski diff --git a/gcc/testsuite/g++.dg/eh/throw1.C b/gcc/testsuite/g++.dg/eh/throw1.C new file mode 100644 index 00000000000..6a3cb2c35ca --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/throw1.C @@ -0,0 +1,9 @@ +class S +{ +public: + S(){} +}; + +int foo(char* m1) { + throw (m1 ? S() : S()); +} diff --git a/gcc/testsuite/g++.dg/expr/sizeof3.C b/gcc/testsuite/g++.dg/expr/sizeof3.C new file mode 100644 index 00000000000..31338b0b189 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/sizeof3.C @@ -0,0 +1,4 @@ +// PR c++/15337 + +class CCC; +int main() { sizeof(CCC); return 0; } // { dg-error ".*CCC.*" } diff --git a/gcc/testsuite/g++.dg/template/access14.C b/gcc/testsuite/g++.dg/template/access14.C new file mode 100644 index 00000000000..047f9258f2f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access14.C @@ -0,0 +1,16 @@ +// PR c++/14777 + +template +struct B +{ +protected: + typedef int M; +}; + +template +struct A : B { + typedef typename B::M N; + A (int = N ()); +}; + +A a = A (); diff --git a/gcc/testsuite/g++.dg/template/enum1.C b/gcc/testsuite/g++.dg/template/enum1.C new file mode 100644 index 00000000000..eaeb12c9c4d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/enum1.C @@ -0,0 +1,5 @@ +// PR c++/15554 + +template struct T1 { enum { N = 3 }; }; +template struct T2 { enum { N = 3, N1 = T1::N }; }; +