From f2fe30af839aaa7d0ad617d739f22eae41181042 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 4 Jul 2011 17:44:04 -0400 Subject: [PATCH] DR 1207 PR c++/49589 DR 1207 PR c++/49589 * mangle.c (write_expression): Handle 'this'. * parser.c (cp_parser_postfix_dot_deref_expression): Allow incomplete *this. * semantics.c (potential_constant_expression_1): Check that DECL_CONTEXT is set on 'this'. From-SVN: r175835 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/mangle.c | 5 +++++ gcc/cp/parser.c | 6 +++++- gcc/cp/semantics.c | 3 ++- gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/abi/mangle48.C | 23 +++++++++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/mangle48.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7eb01d61771..90a80ee2f14 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,13 @@ 2011-07-04 Jason Merrill + DR 1207 + PR c++/49589 + * mangle.c (write_expression): Handle 'this'. + * parser.c (cp_parser_postfix_dot_deref_expression): Allow + incomplete *this. + * semantics.c (potential_constant_expression_1): Check that + DECL_CONTEXT is set on 'this'. + * error.c (dump_template_bindings): Don't print typenames for a partial instantiation. (dump_function_decl): If we aren't printing function arguments, diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 134c9ea7f19..81b772f6316 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -2495,6 +2495,11 @@ write_expression (tree expr) else if (TREE_CODE_CLASS (code) == tcc_constant || (abi_version_at_least (2) && code == CONST_DECL)) write_template_arg_literal (expr); + else if (code == PARM_DECL && DECL_ARTIFICIAL (expr)) + { + gcc_assert (!strcmp ("this", IDENTIFIER_POINTER (DECL_NAME (expr)))); + write_string ("fpT"); + } else if (code == PARM_DECL) { /* A function parameter used in a late-specified return type. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d79326d2808..6bb15ed9508 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -5281,7 +5281,11 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser, postfix_expression); scope = NULL_TREE; } - else + /* Unlike the object expression in other contexts, *this is not + required to be of complete type for purposes of class member + access (5.2.5) outside the member function body. */ + else if (scope != current_class_ref + && !(processing_template_decl && scope == current_class_type)) scope = complete_type_or_else (scope, NULL_TREE); /* Let the name lookup machinery know that we are processing a class member access expression. */ diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e29705c5782..619c0580e84 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7791,7 +7791,8 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) STRIP_NOPS (x); if (is_this_parameter (x)) { - if (DECL_CONSTRUCTOR_P (DECL_CONTEXT (x)) && want_rval) + if (want_rval && DECL_CONTEXT (x) + && DECL_CONSTRUCTOR_P (DECL_CONTEXT (x))) { if (flags & tf_error) sorry ("use of the value of the object being constructed " diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bcf800ad5b4..d496dbcdb82 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2011-07-04 Jason Merrill + * g++.dg/abi/mangle48.C: New. + * g++.dg/cpp0x/diag1.C: New. * g++.dg/diagnostic/aka1.C: New. diff --git a/gcc/testsuite/g++.dg/abi/mangle48.C b/gcc/testsuite/g++.dg/abi/mangle48.C new file mode 100644 index 00000000000..dc9c492cf00 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle48.C @@ -0,0 +1,23 @@ +// Testcase for 'this' mangling +// { dg-options -std=c++0x } + +struct B +{ + template U f(); +}; + +struct A +{ + B b; + // { dg-final { scan-assembler "_ZN1A1fIiEEDTcldtdtdefpT1b1fIT_EEEv" } } + template auto f() -> decltype (b.f()); + // { dg-final { scan-assembler "_ZN1A1gIiEEDTcldtptfpT1b1fIT_EEEv" } } + template auto g() -> decltype (this->b.f()); +}; + +int main() +{ + A a; + a.f(); + a.g(); +} -- 2.30.2