public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Marek Polacek <polacek@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	"Joseph S. Myers" <joseph@codesourcery.com>,
	Jason Merrill <jason@redhat.com>, Nathan Sidwell <nathan@acm.org>,
	Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363)
Date: Tue, 11 Dec 2018 23:08:00 -0000	[thread overview]
Message-ID: <61c2ae91-d6c6-03fe-8ae2-a7f97b1d4151@gmail.com> (raw)
In-Reply-To: <20181211225228.GZ21364@redhat.com>

On 12/11/18 3:52 PM, Marek Polacek wrote:
> On Tue, Dec 11, 2018 at 03:46:37PM -0700, Martin Sebor wrote:
>> On 12/11/18 1:47 PM, Jakub Jelinek wrote:
>>> On Tue, Dec 11, 2018 at 01:36:58PM -0700, Martin Sebor wrote:
>>>> Attached is an updated version of the patch that restores
>>>> the original behavior for the positional argument validation
>>>> (i.e., prior to r266195) for integral types except bool as
>>>> discussed.
>>>
>>> I thought Jason wanted to also warn for scoped enums in C++.
>>
>> I missed that.  It seems needlessly restrictive to me to reject
>> the preferred kind of an enum when ordinary enums are accepted.
>> Jason, can you confirm that you really want a warning for B
>> below when there is none for A (GCC 8 doesn't complain about
>> either, Clang complains about both, ICC about neither when
>> using alloc_size -- it doesn't understand alloc_align):
>>
>>    enum A { /* ... */ };
>>    __attribute__ ((alloc_align (1))) void* f (A);
>>
>>    enum class B { /* ... */ };
>>    __attribute__ ((alloc_align (1))) void* g (B);
>>
>> The only use case I can think of for enums is in APIs that try
>> to restrict the available choices of alignment to those of
>> the enumerators.  In that use case, I would expect it to make
>> no difference whether the enum is ordinary or the scoped kind.
> 
> The reason was that C++ scoped enumerations don't implicitly convert to
> integral types.

I'm not sure we're talking about the same thing.  There is no
conversion in the use case I described, the attribute argument
just refers to the function parameter, and the function is called
with an argument of the enumerated type of the parameter.  Like
this:

   enum class Alignment { a4 = 4, a8 = 8 };

   __attribute__ ((alloc_align (1))) void*
   aligned_alloc (Alignment, size_t);

   void *p = aligned_alloc (Alignment::a8, 32);

My question is: if we think it makes sense to accept this use
case with ordinary enums why would we not want to make it possible
with scoped enums?  People tend to think of the latter as preferable
over the former.

Martin

  reply	other threads:[~2018-12-11 23:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10 23:30 Martin Sebor
2018-12-11  7:17 ` Jakub Jelinek
2018-12-11 15:14   ` Jason Merrill
2018-12-11 15:43   ` Marek Polacek
2018-12-11 16:59   ` Martin Sebor
2018-12-11 18:15     ` Marek Polacek
2018-12-11 19:43       ` Martin Sebor
2018-12-11 18:16     ` Joseph Myers
2018-12-11 19:46       ` Martin Sebor
2018-12-11 20:09         ` Jason Merrill
2018-12-11 20:37   ` Martin Sebor
2018-12-11 20:48     ` Jakub Jelinek
2018-12-11 22:46       ` Martin Sebor
2018-12-11 22:52         ` Marek Polacek
2018-12-11 23:08           ` Martin Sebor [this message]
2018-12-11 23:19             ` Jason Merrill
2018-12-18 21:42               ` Martin Sebor
2019-01-03 22:12                 ` PING #2 " Martin Sebor
2019-01-04 20:56                   ` Joseph Myers
2019-01-06 10:27     ` Jakub Jelinek

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=61c2ae91-d6c6-03fe-8ae2-a7f97b1d4151@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=nathan@acm.org \
    --cc=polacek@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).