[cfe-dev] overloadable + C string literal looks like a bug, seeking confirmation

Tom Honermann via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 16 07:40:18 PDT 2021


On 4/16/2021 8:05 AM, Aaron Ballman via cfe-dev wrote:
> On Thu, Apr 15, 2021 at 6:10 PM Jon Chesterfield via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> Just opened https://urldefense.com/v3/__https://bugs.llvm.org/show_bug.cgi?id=49978__;!!A4F2R9G_pg!KQoRD0xNIzyyey_uDcossBECcs23GC4qIW4UypD3pfxdIgQCRqSZ7a39rV2jlHB5$  with the default CC as I'm not sure who does C front end stuff. Seeking confirmation that this is considered a bug by other people.
>>
>> __attribute__((overloadable) void func(char *);
>> __attribute__((overloadable) void func(const char *);
>> void call(void)
>> {
>>    func("ambiguous");
>> }
>>
>> I think "ambiguous" should decay to a char* and pick the char* overload. Something of an edge case because "literals" have different types between C and C++, and overloadable is an extension anyway.
> FWIW, I think this is a bug. I think in C, this should pick the char *
> overload because that's the type of the string literal.

Agreed, and that would be consistent with _Generic:

void func_nonconst(char *);
void func_const(const char *);
#define func(X)                        \
   _Generic((X),                        \
            char*: func_nonconst,       \
            const char*: func_const)(X)
void call(void)
{
   func("not ambiguous; calls func_nonconst()");
}

Tom.

>
> ~Aaron
>
>> Thanks
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> https://urldefense.com/v3/__https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev__;!!A4F2R9G_pg!KQoRD0xNIzyyey_uDcossBECcs23GC4qIW4UypD3pfxdIgQCRqSZ7a39rVc11mCH$
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://urldefense.com/v3/__https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev__;!!A4F2R9G_pg!KQoRD0xNIzyyey_uDcossBECcs23GC4qIW4UypD3pfxdIgQCRqSZ7a39rVc11mCH$


More information about the cfe-dev mailing list