public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
@ 2011-05-22  4:38 Fabien Chêne
  2011-05-22 13:37 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Fabien Chêne @ 2011-05-22  4:38 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill

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

Hi,

As discussed off-list with Jason, it would be better to use permerror
instead of error when diagnosing uninitialized const or reference
members. At least for 4.6.
That would be usefull to provide a transition for invalid code that
exploits the following accept-invalids: PR 25811, PR 43719, PR 44086.
I have changed error to permerror only for the cases where it was
needed for the PR listed above.

OK for the 4.6 branch ?

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

-- 
Fabien

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

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/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 173980)
+++ gcc/cp/init.c	(working copy)
@@ -1913,8 +1913,9 @@ diagnose_uninitialized_cst_or_ref_member
 	  if (complain)
 	    {
 	      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);
 	      inform (DECL_SOURCE_LOCATION (field),
@@ -1928,10 +1929,12 @@ diagnose_uninitialized_cst_or_ref_member
 	  if (complain)
 	    {
 	      if (using_new)
-		error ("uninitialized const member in %q#T "
-		       "using %<new%> without new-initializer", origin);
+		permerror (input_location,
+			   "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", origin);
 	      inform (DECL_SOURCE_LOCATION (field),
 		      "%qD should be initialized", field);
 	    }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
  2011-05-22  4:38 [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive Fabien Chêne
@ 2011-05-22 13:37 ` Jason Merrill
  2011-05-24 21:43   ` Fabien Chêne
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-22 13:37 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

I think you also need something to avoid returning error_mark_node from 
build_new_1.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
  2011-05-22 13:37 ` Jason Merrill
@ 2011-05-24 21:43   ` Fabien Chêne
  2011-05-25  8:41     ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Fabien Chêne @ 2011-05-24 21:43 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

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

2011/5/22 Jason Merrill <jason@redhat.com>:
> I think you also need something to avoid returning error_mark_node from
> build_new_1.

Indeed. I have also added two testcases to check sfinae on 'new T',
with and without -fpermissive, which leads to a different result.
Tested x86_64-unknown-linux-gnu.
OK for 4.6 ?

I would like to add the testcase pr25811-3.C to Trunk, is it OK ?

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,41 @@
+// { 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
+
+void f()
+{
+  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,41 @@
+// { 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
+
+void f()
+{
+  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,14 +1910,18 @@ diagnose_uninitialized_cst_or_ref_member
 
       if (TREE_CODE (field_type) == REFERENCE_TYPE)
 	{
-	  ++ error_count;
+	  if (!permissive || !using_new)
+	    ++ error_count;
+	    
 	  if (complain)
 	    {
 	      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);
 	    }
@@ -1924,14 +1929,19 @@ diagnose_uninitialized_cst_or_ref_member
 
       if (CP_TYPE_CONST_P (field_type))
 	{
-	  ++ error_count;
+	  if (!permissive)
+	    ++ error_count;
+
 	  if (complain)
 	    {
 	      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);
 	    }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
  2011-05-24 21:43   ` Fabien Chêne
@ 2011-05-25  8:41     ` Jason Merrill
  2011-05-25  8:47       ` Fabien Chêne
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-25  8:41 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

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.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
  2011-05-25  8:41     ` Jason Merrill
@ 2011-05-25  8:47       ` Fabien Chêne
  2011-05-25 13:53         ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Fabien Chêne @ 2011-05-25  8:47 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

[-- 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))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive
  2011-05-25  8:47       ` Fabien Chêne
@ 2011-05-25 13:53         ` Jason Merrill
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2011-05-25 13:53 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

OK, thanks.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-05-25 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-22  4:38 [ C++ 4.6 Patch] allow uninitialized const or reference members with -fpermissive 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
2011-05-25 13:53         ` Jason Merrill

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).