OSDN Git Service

DR 1207
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Jul 2011 21:44:04 +0000 (21:44 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Jul 2011 21:44:04 +0000 (21:44 +0000)
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'.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175835 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/abi/mangle48.C [new file with mode: 0644]

index 7eb01d6..90a80ee 100644 (file)
@@ -1,5 +1,13 @@
 2011-07-04  Jason Merrill  <jason@redhat.com>
 
+       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,
index 134c9ea..81b772f 100644 (file)
@@ -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.  */
index d79326d..6bb15ed 100644 (file)
@@ -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.  */
index e29705c..619c058 100644 (file)
@@ -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 "
index bcf800a..d496dbc 100644 (file)
@@ -1,5 +1,7 @@
 2011-07-04  Jason Merrill  <jason@redhat.com>
 
+       * 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 (file)
index 0000000..dc9c492
--- /dev/null
@@ -0,0 +1,23 @@
+// Testcase for 'this' mangling
+// { dg-options -std=c++0x }
+
+struct B
+{
+  template <class U> U f();
+};
+
+struct A
+{
+  B b;
+  // { dg-final { scan-assembler "_ZN1A1fIiEEDTcldtdtdefpT1b1fIT_EEEv" } }
+  template <class U> auto f() -> decltype (b.f<U>());
+  // { dg-final { scan-assembler "_ZN1A1gIiEEDTcldtptfpT1b1fIT_EEEv" } }
+  template <class U> auto g() -> decltype (this->b.f<U>());
+};
+
+int main()
+{
+  A a;
+  a.f<int>();
+  a.g<int>();
+}