diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 0eefa740dc56a15b8c13ee41169c98dfe750552d..3fc73442da54c6981dcb2b121d6fa6e106aab3ee 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -8262,7 +8262,7 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser,
       tree type = TREE_TYPE (postfix_expression);
       /* If we don't have a (type-dependent) object of class type, use
 	 typeof to figure out the type of the object.  */
-      if (type == NULL_TREE)
+      if (type == NULL_TREE || is_auto (type))
 	type = finish_typeof (postfix_expression);
       parser->context->object_type = type;
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto57.C b/gcc/testsuite/g++.dg/cpp0x/auto57.C
new file mode 100644
index 0000000000000000000000000000000000000000..fedcfde2f0c5372ff6524789aa3601086d2d958d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto57.C
@@ -0,0 +1,15 @@
+// PR c++/105734
+// { dg-do compile { target c++11 } }
+
+namespace N {
+  struct A { };
+  A f(A);
+}
+
+template <class T>
+void bar() {
+  auto m = f(T());
+  m.~A();
+}
+
+void foo() { bar<N::A>(); }