public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
Date: Wed, 30 Mar 2022 09:03:55 -0400	[thread overview]
Message-ID: <b3fcd9c0-71ab-e278-341a-f8a5e93359e3@redhat.com> (raw)
In-Reply-To: <bea4a5ad-1808-28f3-b885-5cf1dd07ad13@idea>

On 3/30/22 08:56, Patrick Palka wrote:
> On Tue, 29 Mar 2022, Jason Merrill wrote:
> 
>> On 3/29/22 15:22, Patrick Palka wrote:
>>> Here we're crashing when diagnosing a failed __is_constructible constraint
>>> because diagnose_atomic_constraint don't know how to diagnose a trait
>>> that diagnose_trait_expr doesn't specifically handle.  This patch fixes
>>> this by falling through to the default case in this situation.
>>>
>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
>>> trunk and perhaps 11?
>>
>> Hmm, it seems reasonable, but I think it would be better to actually handle
>> all the traits.  Removing the default, I get
>>
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_BASES’ not handled
>>> in switch [-Wswitch]
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_DIRECT_BASES’ not
>>> handled in switch [-Wswitch]
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_UNDERLYING_TYPE’ not
>>> handled in switch [-Wswitch]
>>
>> These we don't need to handle.
>>
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS’ not handled in switch \
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_AGGREGATE’ not
>>> handled in switch [-Wswitch]
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_IS_TRIVIALLY_ASSIGNABLE’ not handled in switch [-Wswit\
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_IS_TRIVIALLY_CONSTRUCTIBLE’ not handled in switch [-Ws\
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_IS_TRIVIALLY_COPYABLE’ not handled in switch [-Wswitch\
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_ASSIGNABLE’ not
>>> handled in switch [-Wswitch]
>>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_CONSTRUCTIBLE’
>>> not handled in switch [-Wswitch]
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_IS_NOTHROW_ASSIGNABLE’ not handled in switch [-Wswitch\
>>> constraint.cc:3585:10: warning: enumeration value
>>> ‘CPTK_IS_NOTHROW_CONSTRUCTIBLE’ not handled in switch [-Wswi\
>>
>> These we should.
>>
>> I think we should leave off the default so that when we add more traits we get
>> a warning that we need to handle them here.
> 
> Sounds good, like so?

Let's leave a comment about why there's no 'default'.  OK with that change.

> -- >8 --
> 
> Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474]
> 
> Here we're crashing when diagnosing a failed __is_constructible constraint
> because diagnose_trait_expr doesn't recognize this trait (along with a
> bunch of other traits).  Fix this by adding handling for all remaining
> traits and removing the default case so that when we add a new trait we
> get a warning that diagnose_trait_expr needs to handle it.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk and perhaps 11?
> 
> 	PR c++/100474
> 
> gcc/cp/ChangeLog:
> 
> 	* constraint.cc (diagnose_trait_expr): Handle all remaining
> 	traits appropriately.  Remove default case.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-traits3.C: New test.
> ---
>   gcc/cp/constraint.cc                          | 41 +++++++++++-
>   gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 66 +++++++++++++++++++
>   2 files changed, 106 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
> 
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index c5a991b9e71..b970ac9772d 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3654,7 +3654,46 @@ diagnose_trait_expr (tree expr, tree args)
>       case CPTK_IS_UNION:
>         inform (loc, "  %qT is not a union", t1);
>         break;
> -    default:
> +    case CPTK_IS_AGGREGATE:
> +      inform (loc, "  %qT is not an aggregate", t1);
> +      break;
> +    case CPTK_IS_TRIVIALLY_COPYABLE:
> +      inform (loc, "  %qT is not trivially copyable", t1);
> +      break;
> +    case CPTK_IS_ASSIGNABLE:
> +      inform (loc, "  %qT is not assignable from %qT", t1, t2);
> +      break;
> +    case CPTK_IS_TRIVIALLY_ASSIGNABLE:
> +      inform (loc, "  %qT is not trivially assignable from %qT", t1, t2);
> +      break;
> +    case CPTK_IS_NOTHROW_ASSIGNABLE:
> +      inform (loc, "  %qT is not %<nothrow%> assignable from %qT", t1, t2);
> +      break;
> +    case CPTK_IS_CONSTRUCTIBLE:
> +      if (!t2)
> +	inform (loc, "  %qT is not default constructible", t1);
> +      else
> +	inform (loc, "  %qT is not constructible from %qE", t1, t2);
> +      break;
> +    case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
> +      if (!t2)
> +	inform (loc, "  %qT is not trivially default constructible", t1);
> +      else
> +	inform (loc, "  %qT is not trivially constructible from %qE", t1, t2);
> +      break;
> +    case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
> +      if (!t2)
> +	inform (loc, "  %qT is not %<nothrow%> default constructible", t1);
> +      else
> +	inform (loc, "  %qT is not %<nothrow%> constructible from %qE", t1, t2);
> +      break;
> +    case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
> +      inform (loc, "  %qT does not have unique object representations", t1);
> +      break;
> +    case CPTK_BASES:
> +    case CPTK_DIRECT_BASES:
> +    case CPTK_UNDERLYING_TYPE:
> +      /* We shouldn't see these non-expression traits.  */
>         gcc_unreachable ();
>       }
>   }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
> new file mode 100644
> index 00000000000..f20608b6918
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
> @@ -0,0 +1,66 @@
> +// PR c++/100474
> +// { dg-do compile { target c++20 } }
> +
> +struct S { S() = delete; S(const S&); };
> +
> +template<class T>
> +concept Aggregate = __is_aggregate(T);
> +// { dg-message "'S' is not an aggregate" "" { target *-*-* } .-1  }
> +
> +template<class T>
> +concept TriviallyCopyable = __is_trivially_copyable(T);
> +// { dg-message "'S' is not trivially copyable" "" { target *-*-* } .-1  }
> +
> +template<class T, class U>
> +concept Assignable = __is_assignable(T, U);
> +// { dg-message "'S' is not assignable from 'int'" "" { target *-*-* } .-1  }
> +
> +template<class T, class U>
> +concept TriviallyAssignable = __is_trivially_assignable(T, U);
> +// { dg-message "'S' is not trivially assignable from 'int'" "" { target *-*-* } .-1  }
> +
> +template<class T, class U>
> +concept NothrowAssignable = __is_nothrow_assignable(T, U);
> +// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1  }
> +
> +template<class T, class... Args>
> +concept Constructible = __is_constructible(T, Args...);
> +// { dg-message "'S' is not default constructible" "" { target *-*-* } .-1  }
> +// { dg-message "'S' is not constructible from 'int'" "" { target *-*-* } .-2  }
> +// { dg-message "'S' is not constructible from 'int, char'" "" { target *-*-* } .-3  }
> +
> +template<class T, class... Args>
> +concept TriviallyConstructible = __is_trivially_constructible(T, Args...);
> +// { dg-message "'S' is not trivially default constructible" "" { target *-*-* } .-1  }
> +// { dg-message "'S' is not trivially constructible from 'int'" "" { target *-*-* } .-2  }
> +// { dg-message "'S' is not trivially constructible from 'int, char'" "" { target *-*-* } .-3  }
> +
> +template<class T, class... Args>
> +concept NothrowConstructible = __is_nothrow_constructible(T, Args...);
> +// { dg-message "'S' is not 'nothrow' default constructible" "" { target *-*-* } .-1  }
> +// { dg-message "'S' is not 'nothrow' constructible from 'int'" "" { target *-*-* } .-2  }
> +// { dg-message "'S' is not 'nothrow' constructible from 'int, char'" "" { target *-*-* } .-3  }
> +
> +template<class T>
> +concept UniqueObjReps = __has_unique_object_representations(T);
> +// { dg-message "'S' does not have unique object representations" "" { target *-*-* } .-1  }
> +
> +static_assert(Aggregate<S>); // { dg-error "assert" }
> +static_assert(TriviallyCopyable<S>); // { dg-error "assert" }
> +static_assert(Assignable<S, int>); // { dg-error "assert" }
> +static_assert(TriviallyAssignable<S, int>); // { dg-error "assert" }
> +static_assert(NothrowAssignable<S, int>); // { dg-error "assert" }
> +
> +static_assert(Constructible<S>); // { dg-error "assert" }
> +static_assert(Constructible<S, int>); // { dg-error "assert" }
> +static_assert(Constructible<S, int, char>); // { dg-error "assert" }
> +
> +static_assert(TriviallyConstructible<S>); // { dg-error "assert" }
> +static_assert(TriviallyConstructible<S, int>); // { dg-error "assert" }
> +static_assert(TriviallyConstructible<S, int, char>); // { dg-error "assert" }
> +
> +static_assert(NothrowConstructible<S>); // { dg-error "assert" }
> +static_assert(NothrowConstructible<S, int>); // { dg-error "assert" }
> +static_assert(NothrowConstructible<S, int, char>); // { dg-error "assert" }
> +
> +static_assert(UniqueObjReps<S>); // { dg-error "assert" }


      reply	other threads:[~2022-03-30 13:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 19:22 Patrick Palka
2022-03-29 20:53 ` Jason Merrill
2022-03-30 12:56   ` Patrick Palka
2022-03-30 13:03     ` Jason Merrill [this message]

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=b3fcd9c0-71ab-e278-341a-f8a5e93359e3@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@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).