| Issue |
175294
|
| Summary |
C++ function overloading bug
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
VisionShilin
|
The C++ function overloading worked incorrectly when calling a overloading function with a const sring parameter.
The compiler matched a function with a const string parameter incorrectly to a function with a bool parameter.
Both clang++ and g++ have this problem.
Here is the source codes.
//test.cpp
#include <iostream>
#include <string>
class A{
public:
A(std::string name){
std::cout << "Constructor A(string)" << std::endl;
}
A(bool b){
std::cout << "Constructor A(bool)" << std::endl;
}
void f1(std::string name){
std::cout << "f1(string)" << std::endl;
}
void f1(bool b){
std::cout << "f1(bool)" << std::endl;
}
};
int main()
{
const std::string s = "sss";
A a1(s); //correct
A a2("sss"); //wrong!!!
A a3(true); //correct
a1.f1(s); //correct
a1.f1("sss"); //wrong!!!
a1.f1(true); //correct
}
//g++ test.cpp -o test
//clang++ test.cpp -o test
/*
$ g++ --version
g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ clang++ --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
*/
The results of the codes should be :
Constructor A(string)
Constructor A(string)
Constructor A(bool)
f1(string)
f1(string)
f1(bool)
instead of:
Constructor A(string)
Constructor A(bool)
Constructor A(bool)
f1(string)
f1(bool)
f1(bool)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs