C++ Error: call of overloaded function is ambiguous


I have defined a function in one file -

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void c2bc( std::string& filename, std::string& outname ) {
std::ostringstream cmd;
cmd << "clang-3.6 -emit-llvm -O0 -g " << filename << " -o " << outname << " -c";
if( system( cmd.str().c_str() ) != 0 ) exit(1);


program* parse_cpp_file( helpers::z3interf& z3_, std::string& cfile ) {
std::unique_ptr<llvm::Module> module;
llvm::SMDiagnostic err;
llvm::LLVMContext& context = llvm::getGlobalContext();

std::string bc_file = cfile+".bc";

c2bc( cfile, bc_file);
 module = llvm::parseIRFile( bc_file, err, context);
  if( module.get() == 0 ) {
    // give err msg
  }

  program* p = new program(z3_);
  
  return p;
 }


And declared the same in header file as follows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef TARA_CINPUT_PROGRAM_H
#define TARA_CINPUT_PROGRAM_H
namespace cinput {
      class loc{
   public:
      unsigned line;
      unsigned col;
      std::string file;
    };
    class program {
    public:
     ....
    };
    void c2bc( std::string& filename, std::string& outname );
}
#endif 


Now I'm trying to call this function from another .cpp file like this

1
2
3
4
5
6
7
void trace_analysis::input(string input_file, mm_t mm){
...
std::string bc_file = input_file+".bc";
if(input_file.find(".c") != std::string::npos){
cinput::c2bc( input_file, bc_file);
 }
}

I have included the header of the first file into the latter one. Compilation gives me the error

1
2
3
4
5
6
7
8
9
error: call of overloaded ‘c2bc(std::__cxx11::string&,   
std::__cxx11::string&)’ is ambiguous
 c2bc( cfile, bc_file);
... note: suggested alternative:
In file included from /home/.../src/library/api/trace_analysis.cpp:34:0:
/home/../src/library/cinput/cinput.h:47:8: note:   ‘tara::cinput::c2bc’
   void c2bc( std::string& filename, std::string& outname );

                     ^


I have spent a lot of time on this trying to figure it out. Any help is much appreciated. Thanks in advance!
Last edited on
Do you have include guards in your header file? The compiler seems to be seeing the function multiple times, hence the "call of overloaded" message.

Also please use code tags when posting your code.
Last edited on
Yes I do have include guards. I've edited the code in the question. What else do you think could be the issue?
First it would be helpful if you included all compiler errors exactly as they appear in your development environment. There should probably be more error messages related to this issue, and the error you did post should have more information, ie. the line number where the error was detected.

Second how are you compiling the source file? You didn't by chance #include the source file, did you?

There error you are reporting refers to line 14 of your first segment. Are both functions shown in that that file snippet contained in the cinput namespace? It's hard to tell what's going on because you never close the first function in the snippet. What lies between lines 4 and 7?
@doug4 It is included in the cinput namespace. Made changes in the question!
@jib I've added the error messages. Sorry I'm a noob here thanks for being patient! I didn't #include the source file.
> Compilation gives me the error
¿is that the full error message?
¿isn't there a part that says note: candidate?


> ‘tara::cinput::c2bc’
¿the hell is tara?
Please provide enough code to reproduce your issue.
This has been resolved.
Would you mind telling us what caused the problem?

It turns out I actually wanted to call parse_cpp_file function and not c2bc since parse_cpp_file calls c2bc.
This worked just fine.

1
2
3
4
5
6
void trace_analysis::input(string input_file, mm_t mm){
if( input_file.find(".c") != std::string::npos ) {
 cinput::program* p = cinput::parse_cpp_file( z3, input_file );
}
...
}


I wasn't sure whether this would add value to the community.
Last edited on
Topic archived. No new replies allowed.