public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Fabien Chêne" <fabien.chene@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
Date: Wed, 25 May 2011 08:47:00 -0000	[thread overview]
Message-ID: <BANLkTi=TooRmyQ-nQ9k08dvz8MQdN3B-WA@mail.gmail.com> (raw)
In-Reply-To: <4DDC5D4A.1070709@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

2011/5/25 Jason Merrill <jason@redhat.com>:
> On 05/24/2011 04:40 PM, Fabien Chêne wrote:
>>
>> Indeed. I have also added two testcases to check sfinae on 'new T',
>> with and without -fpermissive, which leads to a different result.
>
> We don't want to do that; overload resolution should always produce the same
> result.  We can only be permissive in non-SFINAE context.

Well, here is an updated patch. Testing in progress ... (it works for
the added testcases)
OK for 4.6 if it succeeds ?
OK to commit testcases pr25811-3.C and pr25811-4.C to Trunk ?

gcc/cp/ChangeLog:

2011-05-25  Fabien Chêne  <fabien@gcc.gnu.org>
       * init.c (diagnose_uninitialized_cst_or_ref_member_1): Use
       permerror instead of error, adjust the error count.

gcc/testsuite/ChangeLog:

2011-05-25  Fabien Chêne  <fabien@gcc.gnu.org>
       * g++.dg/init/pr25811-2.C: New.
       * g++.dg/init/pr25811-3.C: New.
       * g++.dg/init/pr25811-4.C: New.

-- 
Fabien

[-- Attachment #2: perm_cst_ref_diag.patch --]
[-- Type: application/octet-stream, Size: 5217 bytes --]

Index: gcc/testsuite/g++.dg/init/pr25811-4.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr25811-4.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/pr25811-4.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-options "-fpermissive" }
+
+struct A { int const i; };
+struct B { int& i; };
+struct C { int i; };
+
+template< class T >
+class is_constructible_via_new_without_initializer
+{
+    template<int> class size {};
+
+    typedef char yes_type;
+    struct no_type { char data[2]; };
+
+    template <class U>
+    static yes_type sfinae (size< sizeof (new U) >*);
+
+    template <class U>
+    static no_type sfinae (...);
+
+public:
+  static const bool value = sizeof (sfinae<T>(0)) == sizeof (yes_type);
+};
+
+#define JOIN( X, Y ) DO_JOIN( X, Y )
+#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
+#define DO_JOIN2( X, Y ) X##Y
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
+#else
+#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
+#endif
+
+STATIC_ASSERT (!is_constructible_via_new_without_initializer<A>::value);
+STATIC_ASSERT (!is_constructible_via_new_without_initializer<B>::value);
+STATIC_ASSERT (is_constructible_via_new_without_initializer<C>::value);
Index: gcc/testsuite/g++.dg/init/pr25811-2.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr25811-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/pr25811-2.C	(revision 0)
@@ -0,0 +1,26 @@
+// { dg-do compile }
+// { dg-options -fpermissive }
+
+struct A
+{
+  int const i; // { dg-message "should be initialized" }
+};
+
+struct B
+{
+  int& r; // { dg-message "should be initialized" }
+};
+
+struct C
+{
+  int const i : 1; // { dg-message "should be initialized" }
+};
+
+void f()
+{
+  new A;  // { dg-warning "uninitialized" }
+  new B;  // { dg-warning "uninitialized" }
+  new C;  // { dg-warning "uninitialized" }
+  C c;    // { dg-warning "uninitialized" }
+  A a[1]; // { dg-warning "uninitialized" }
+}
Index: gcc/testsuite/g++.dg/init/pr25811-3.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr25811-3.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/pr25811-3.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-do compile }
+
+struct A { int const i; };
+struct B { int& i; };
+struct C { int i; };
+
+template< class T >
+class is_constructible_via_new_without_initializer
+{
+    template<int> class size {};
+
+    typedef char yes_type;
+    struct no_type { char data[2]; };
+
+    template <class U>
+    static yes_type sfinae (size< sizeof (new U) >*);
+
+    template <class U>
+    static no_type sfinae (...);
+
+public:
+  static const bool value = sizeof (sfinae<T>(0)) == sizeof (yes_type);
+};
+
+#define JOIN( X, Y ) DO_JOIN( X, Y )
+#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
+#define DO_JOIN2( X, Y ) X##Y
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
+#else
+#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
+#endif
+
+STATIC_ASSERT (!is_constructible_via_new_without_initializer<A>::value);
+STATIC_ASSERT (!is_constructible_via_new_without_initializer<B>::value);
+STATIC_ASSERT (is_constructible_via_new_without_initializer<C>::value);
+
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 173980)
+++ gcc/cp/init.c	(working copy)
@@ -1891,6 +1891,7 @@ diagnose_uninitialized_cst_or_ref_member
 {
   tree field;
   int error_count = 0;
+  bool permissive = global_dc->permissive;
 
   if (type_has_user_provided_constructor (type))
     return 0;
@@ -1909,32 +1910,45 @@ diagnose_uninitialized_cst_or_ref_member
 
       if (TREE_CODE (field_type) == REFERENCE_TYPE)
 	{
-	  ++ error_count;
 	  if (complain)
 	    {
+	      if (!permissive || !using_new)
+		++ error_count;
+
 	      if (using_new)
-		error ("uninitialized reference member in %q#T "
-		       "using %<new%> without new-initializer", origin);
+		  permerror (input_location,
+			     "uninitialized reference member in %q#T "
+			     "using %<new%> without new-initializer", origin);
 	      else
-		error ("uninitialized reference member in %q#T", origin);
+		  error ("uninitialized reference member in %q#T", origin);
+
 	      inform (DECL_SOURCE_LOCATION (field),
 		      "%qD should be initialized", field);
 	    }
+	  else
+	    ++ error_count;
 	}
 
       if (CP_TYPE_CONST_P (field_type))
 	{
-	  ++ error_count;
 	  if (complain)
 	    {
+	      if (!permissive)
+		++ error_count;
+
 	      if (using_new)
-		error ("uninitialized const member in %q#T "
-		       "using %<new%> without new-initializer", origin);
-	      else
-		error ("uninitialized const member in %q#T", origin);
+		permerror (input_location,
+			   "uninitialized const member in %q#T "
+			   "using %<new%> without new-initializer", origin);
+	      else 
+		permerror (input_location,
+			   "uninitialized const member in %q#T", origin);
+
 	      inform (DECL_SOURCE_LOCATION (field),
 		      "%qD should be initialized", field);
 	    }
+	  else
+	    ++ error_count;
 	}
 
       if (CLASS_TYPE_P (field_type))

  reply	other threads:[~2011-05-25  5:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22  4:38 Fabien Chêne
2011-05-22 13:37 ` Jason Merrill
2011-05-24 21:43   ` Fabien Chêne
2011-05-25  8:41     ` Jason Merrill
2011-05-25  8:47       ` Fabien Chêne [this message]
2011-05-25 13:53         ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=TooRmyQ-nQ9k08dvz8MQdN3B-WA@mail.gmail.com' \
    --to=fabien.chene@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).