]> gcc.gnu.org Git - gcc.git/commitdiff
DR 1359 PR c++/51675
authorJason Merrill <jason@redhat.com>
Mon, 2 Jan 2012 17:53:28 +0000 (12:53 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 2 Jan 2012 17:53:28 +0000 (12:53 -0500)
DR 1359
PR c++/51675
* method.c (walk_field_subobs): Don't check for uninitialized
fields in a union.
(synthesized_method_walk): Check here.

From-SVN: r182810

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-union2.C [new file with mode: 0644]

index 7668a7b6e089e1c2ceea72cab8ffb955f1c13934..9eb688263a77fcd3cf5cbb3653476f23280ed750 100644 (file)
@@ -1,5 +1,11 @@
 2012-01-02  Jason Merrill  <jason@redhat.com>
 
+       DR 1359
+       PR c++/51675
+       * method.c (walk_field_subobs): Don't check for uninitialized
+       fields in a union.
+       (synthesized_method_walk): Check here.
+
        DR 325
        PR c++/51666
        * parser.c (cp_parser_cache_defarg): Split out...
index 8101f8a11c7c4ea1a5365753f93090f09117c1a0..cf2a713aa2a8f3437370d9ee79e155c3ccdd4c60 100644 (file)
@@ -1063,7 +1063,8 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
          /* For an implicitly-defined default constructor to be constexpr,
             every member must have a user-provided default constructor or
             an explicit initializer.  */
-         if (constexpr_p && !CLASS_TYPE_P (mem_type))
+         if (constexpr_p && !CLASS_TYPE_P (mem_type)
+             && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
            {
              *constexpr_p = false;
              if (msg)
@@ -1208,12 +1209,19 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
      resolution, so a constructor can be trivial even if it would otherwise
      call a non-trivial constructor.  */
   if (expected_trivial
-      && !diag
       && (!copy_arg_p || cxx_dialect < cxx0x))
     {
       if (constexpr_p && sfk == sfk_constructor)
-       *constexpr_p = trivial_default_constructor_is_constexpr (ctype);
-      return;
+       {
+         bool cx = trivial_default_constructor_is_constexpr (ctype);
+         *constexpr_p = cx;
+         if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
+           /* A trivial constructor doesn't have any NSDMI.  */
+           inform (input_location, "defaulted default constructor does "
+                   "not initialize any non-static data member");
+       }
+      if (!diag)
+       return;
     }
 
   ++cp_unevaluated_operand;
index e1e0dfeff7d2466af9e4d97fc77bd5ef213ee34b..79d43fac075858c15682f114dfc236b6a7462582 100644 (file)
@@ -1,5 +1,8 @@
 2012-01-02  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51675
+       * g++.dg/cpp0x/constexpr-union2.C: New.
+
        PR c++/51666
        * g++.dg/cpp0x/nsdmi-defer5.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-union2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-union2.C
new file mode 100644 (file)
index 0000000..0bf2aa7
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/51675
+// { dg-options -std=c++0x }
+
+union foo
+{
+  int x = 0;
+  short y;
+
+  constexpr foo() = default;
+};
+
+union bar
+{
+  int x;
+  short y;
+
+  constexpr bar() = default;   // { dg-error "constexpr" }
+};
This page took 0.083426 seconds and 5 git commands to generate.