diff mbox

PR c++/51462 - ICE in cx_check_missing_mem_inits

Message ID m339ckxr1e.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Dec. 16, 2011, 7:19 p.m. UTC
Jason Merrill <jason@redhat.com> writes:

> On 12/16/2011 11:40 AM, Dodji Seketeli wrote:
>> 	      /* It's OK to skip a member with a trivial constexpr ctor.
>> 	         A constexpr ctor that isn't trivial should have been
>> 	         added in by now.  */
>> 	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype));
>>
>> If you think I am trying too hard, maybe I could just get out early
>> from register_constexpr_fundef if errorcount is non-zero?
>
> Let's just check errorcount in this assert.

OK, I am currently testing the patch below.

>
>> [1]:  By the way, I am just curious, why using gcc_checking_assert
>> instead of just gcc_assert?
>
> In general, I think it makes sense to use gcc_checking_assert for
> checks that either are expensive, or check conditions that aren't
> really problematic to deal with if they do occur.  But I haven't been
> particularly methodical about using one or the other.

I see.  Thanks.

gcc/cp/

	PR c++/51462
	* semantics.c (cx_check_missing_mem_inits): Don't assert in case
	of error.

gcc/testsuite/

	PR c++/51462
	* g++.dg/cpp0x/constexpr-99.C: New test.
---
 gcc/cp/semantics.c                        |    3 ++-
 gcc/testsuite/g++.dg/cpp0x/constexpr-99.C |   13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-99.C

Comments

Dodji Seketeli Jan. 2, 2012, 1:12 p.m. UTC | #1
The below passed bootstrap and testing, OK for trunk?

Thanks.

Dodji Seketeli <dodji@redhat.com> a écrit:

> Jason Merrill <jason@redhat.com> writes:
>
>> On 12/16/2011 11:40 AM, Dodji Seketeli wrote:
>>> 	      /* It's OK to skip a member with a trivial constexpr ctor.
>>> 	         A constexpr ctor that isn't trivial should have been
>>> 	         added in by now.  */
>>> 	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype));
>>>
>>> If you think I am trying too hard, maybe I could just get out early
>>> from register_constexpr_fundef if errorcount is non-zero?
>>
>> Let's just check errorcount in this assert.
>
> OK, I am currently testing the patch below.
>
>>
>>> [1]:  By the way, I am just curious, why using gcc_checking_assert
>>> instead of just gcc_assert?
>>
>> In general, I think it makes sense to use gcc_checking_assert for
>> checks that either are expensive, or check conditions that aren't
>> really problematic to deal with if they do occur.  But I haven't been
>> particularly methodical about using one or the other.
>
> I see.  Thanks.
>
> gcc/cp/
>
> 	PR c++/51462
> 	* semantics.c (cx_check_missing_mem_inits): Don't assert in case
> 	of error.
>
> gcc/testsuite/
>
> 	PR c++/51462
> 	* g++.dg/cpp0x/constexpr-99.C: New test.
> ---
>  gcc/cp/semantics.c                        |    3 ++-
>  gcc/testsuite/g++.dg/cpp0x/constexpr-99.C |   13 +++++++++++++
>  2 files changed, 15 insertions(+), 1 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-99.C
>
> diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
> index 2f2a26a..f5d34c1 100644
> --- a/gcc/cp/semantics.c
> +++ b/gcc/cp/semantics.c
> @@ -6021,7 +6021,8 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
>  	      /* It's OK to skip a member with a trivial constexpr ctor.
>  	         A constexpr ctor that isn't trivial should have been
>  	         added in by now.  */
> -	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype));
> +	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype)
> +				   || errorcount != 0);
>  	      continue;
>  	    }
>  	  error ("uninitialized member %qD in %<constexpr%> constructor",
> diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C
> new file mode 100644
> index 0000000..13a5ea3
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C
> @@ -0,0 +1,13 @@
> +// Origin PR c++/51462
> +// { dg-options "-std=c++11" }
> +
> +struct A
> +{
> +  int i = 0;
> +};
> +
> +struct B
> +{
> +  A a;
> +    constexpr B() : a(0) {} // { dg-error "no matching function" }
> +};
> -- 
> 1.7.6.4
Jason Merrill Jan. 2, 2012, 1:25 p.m. UTC | #2
OK.

Jason
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 2f2a26a..f5d34c1 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -6021,7 +6021,8 @@  cx_check_missing_mem_inits (tree fun, tree body, bool complain)
 	      /* It's OK to skip a member with a trivial constexpr ctor.
 	         A constexpr ctor that isn't trivial should have been
 	         added in by now.  */
-	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype));
+	      gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype)
+				   || errorcount != 0);
 	      continue;
 	    }
 	  error ("uninitialized member %qD in %<constexpr%> constructor",
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C
new file mode 100644
index 0000000..13a5ea3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-99.C
@@ -0,0 +1,13 @@ 
+// Origin PR c++/51462
+// { dg-options "-std=c++11" }
+
+struct A
+{
+  int i = 0;
+};
+
+struct B
+{
+  A a;
+    constexpr B() : a(0) {} // { dg-error "no matching function" }
+};