Skip to content
Snippets Groups Projects
  • George Burgess IV's avatar
    2cef254a
    [Sema] Compare bad conversions in overload resolution. · 2cef254a
    George Burgess IV authored
    r280553 introduced an issue where we'd emit ambiguity errors for code
    like:
    
    ```
    void foo(int *, int);
    void foo(unsigned int *, unsigned int);
    
    void callFoo() {
      unsigned int i;
      foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int,
                  // but unsigned int*->unsigned int* is better than
                  // int*->int*.
    }
    ```
    
    This patch fixes this issue by changing how we handle ill-formed (but
    valid) implicit conversions. Candidates with said conversions now always
    rank worse than candidates without them, and two candidates are
    considered to be equally bad if they both have these conversions for
    the same argument.
    
    Additionally, this fixes a case in C++11 where we'd complain about an
    ambiguity in a case like:
    
    ```
    void f(char *, int);
    void f(const char *, unsigned);
    void g() { f("abc", 0); }
    ```
    
    ...Since conversion to char* from a string literal is considered
    ill-formed in C++11 (and deprecated in C++03), but we accept it as an
    extension.
    
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280847 91177308-0d34-0410-b5e6-96231b3b80d8
    2cef254a
    History
    [Sema] Compare bad conversions in overload resolution.
    George Burgess IV authored
    r280553 introduced an issue where we'd emit ambiguity errors for code
    like:
    
    ```
    void foo(int *, int);
    void foo(unsigned int *, unsigned int);
    
    void callFoo() {
      unsigned int i;
      foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int,
                  // but unsigned int*->unsigned int* is better than
                  // int*->int*.
    }
    ```
    
    This patch fixes this issue by changing how we handle ill-formed (but
    valid) implicit conversions. Candidates with said conversions now always
    rank worse than candidates without them, and two candidates are
    considered to be equally bad if they both have these conversions for
    the same argument.
    
    Additionally, this fixes a case in C++11 where we'd complain about an
    ambiguity in a case like:
    
    ```
    void f(char *, int);
    void f(const char *, unsigned);
    void g() { f("abc", 0); }
    ```
    
    ...Since conversion to char* from a string literal is considered
    ill-formed in C++11 (and deprecated in C++03), but we accept it as an
    extension.
    
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280847 91177308-0d34-0410-b5e6-96231b3b80d8
Code owners
Assign users and groups as approvers for specific file changes. Learn more.