[llvm-bugs] [Bug 49978] New: overloadable + string literal => ambiguous

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 15 15:01:53 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49978

            Bug ID: 49978
           Summary: overloadable + string literal => ambiguous
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jonathanchesterfield at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Godbolt https://godbolt.org/z/49j3E6Tjn

Give overloadable functions on const char* and char*,

__attribute__((overloadable))
void func(const char * s) {}

__attribute__((overloadable))
void func(char * s) {}


All the calls below work except the unadorned string literal. This should decay
to a char* (this is C, not C++) and call the char* overload.

<source>:17:5: error: call to 'func' is ambiguous
    func("failure");

void caller()
{
    char mut[4] = "mut";
    const char * cst = "cst";
    func(mut);
    func(cst);
    func((const char*)"cst cast");
    func((char*)"mut cast");
    func(&"explicit ok"[0]);
    func((char[3]){1,2,3});
    func((const char[3]){1,2,3});
    func("failure");
}

This is moderately annoying for some library code intended for openmp so I'm
probably available to fix if there is consensus that this is indeed a bug in
clang.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210415/f55dd1cf/attachment-0001.html>


More information about the llvm-bugs mailing list