This fixes a recent P1.  Here we were giving the "invalid use of incomplete
type" error, but "the operand of the decltype specifier is an unevaluated 
operand"
and so the objects it names are not required to have a definition.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-04-17  Marek Polacek  <pola...@redhat.com>

        PR c++/90124 - bogus error with incomplete type in decltype.
        * typeck.c (build_class_member_access_expr): Check
        cp_unevaluated_operand.

        * g++.dg/cpp0x/decltype70.C: New test.

diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index 03b14024738..7224d9bf9ed 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -2477,7 +2477,8 @@ build_class_member_access_expr (cp_expr object, tree 
member,
          /* We didn't complain above about a currently open class, but now we
             must: we don't know how to refer to a base member before layout is
             complete.  But still don't complain in a template.  */
-         if (!dependent_type_p (object_type)
+         if (!cp_unevaluated_operand
+             && !dependent_type_p (object_type)
              && !complete_type_or_maybe_complain (object_type, object,
                                                   complain))
            return error_mark_node;
diff --git gcc/testsuite/g++.dg/cpp0x/decltype70.C 
gcc/testsuite/g++.dg/cpp0x/decltype70.C
new file mode 100644
index 00000000000..b26aca90651
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/decltype70.C
@@ -0,0 +1,10 @@
+// PR c++/90124
+// { dg-do compile { target c++11 } }
+
+class a {
+public:
+  int b;
+};
+class c : a {
+  auto m_fn1() -> decltype(b);
+};

Reply via email to