PR c++/45908
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Oct 2010 14:35:25 +0000 (14:35 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Oct 2010 14:35:25 +0000 (14:35 +0000)
* typeck.c (cp_build_addr_expr_1): Add check for incomplete types in
code folding offsetof-like computations.

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

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr45908.C [new file with mode: 0644]

index e347e6d..8143763 100644 (file)
@@ -1,3 +1,9 @@
+2010-10-06  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR c++/45908
+       * typeck.c (cp_build_addr_expr_1): Add check for incomplete types in
+       code folding offsetof-like computations.
+
 2010-10-05  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        PR objc++/31125
index b2b8e5f..ff5714d 100644 (file)
@@ -4947,6 +4947,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
       && TREE_CODE (argtype) != METHOD_TYPE
       && argtype != unknown_type_node
       && (val = get_base_address (arg))
+      && COMPLETE_TYPE_P (TREE_TYPE (val))
       && TREE_CODE (val) == INDIRECT_REF
       && TREE_CONSTANT (TREE_OPERAND (val, 0)))
     {
index 8cab44c..187ba7e 100644 (file)
@@ -1,5 +1,9 @@
 2010-10-06  Eric Botcazou  <ebotcazou@adacore.com>
 
+       * g++.dg/cpp0x/pr45908.C: New test.
+
+2010-10-06  Eric Botcazou  <ebotcazou@adacore.com>
+
        * gnat.dg/opt6.ad[sb]: New test.
 
 2010-10-06  Nicola Pero  <nicola.pero@meta-innovation.com>
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr45908.C b/gcc/testsuite/g++.dg/cpp0x/pr45908.C
new file mode 100644 (file)
index 0000000..1a821e5
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/45908
+// Testcase by Jonathan Wakely <redi@gcc.gnu.org>
+
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+
+struct vector {
+    struct iterator { };
+    struct const_iterator { };
+    iterator begin();
+    const_iterator begin() const;
+};
+
+class block {
+    vector v;
+    auto end() const -> decltype(v.begin())
+    { return v.begin(); } // { dg-error "conversion" }
+};