Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Redeclaration of overloaded operator function is incorrectly diagnosed #16004

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR16004
Status NEW
Importance P normal
Reported by Ali (alireza.moshtaghi@synopsys.com)
Reported on 2013-05-14 16:57:57 -0700
Last modified on 2013-05-15 00:24:03 -0700
Version unspecified
Hardware All All
CC dgregor@apple.com, llvm-bugs@lists.llvm.org, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Quuxplusone commented 11 years ago
/* g++ accepts this but clang diagnoses:
   error2.cpp:27:12:
   error: use of overloaded operator '*=' is ambiguous (with
      operand types 'XX' and 'long')
*/
void goo(int, int);
class XX {
public:
    int i;
    XX(int j) : i(j) { }
};

int operator*=(XX b, double j) { return b.i + int(2 * j); }
int operator*=(XX b, long j) { return b.i + int(4 * j); }
void foo(XX &b) {
/* redeclaration of the two operator functions inside foo scope
 * cause the error.
 * why should it matter to clang that these are redeclared? they
 * can't be any different than above functions anyways...
 *
 */
    int operator*=(XX b, double j);
    int operator*=(XX b, long j);

    XX& br = b;
    goo(br *= 9.0, 5);
    goo(br *= 7L, 9);
}