error: expected `;' before ':' token - c++

This error is from the first line, peer : m_peerList
I don't know how to solve this, I tried everything.
const char * peer;
for (peer : m_peerList)
{
if (peer->IsAuth() || !peer->IsValid() || peer->GetChannel() != p->channel) //not the channel we are looking for!
continue;
TMapLocation kMapLocation;
thecore_memcpy(kMapLocation.alMaps, peer->GetMaps(), sizeof(kMapLocation.alMaps));
for (const auto midx :: kMapLocation.alMaps)
{
if (midx == p->lMapIndex)
{
//Get host, and convert to int
char host[16];
strlcpy(host, peer->GetPublicIP(), sizeof(kMapLocation.szHost));
lAddr = inet_addr(host);
//Target port
port = peer->GetListenPort();
break;
}
}
if (lAddr && port) //We already obtained them
break;
}
Error:
error: expected `;' before ':' token
If you can help me, I would be so much thank to you.

It must be compiled with the flag -std=c++11 or -std=c++14 or -std=c++17 . Also look at the second for-loop, it has an error.

There is a typo
for (const auto midx :: kMapLocation.alMaps)
should be
for (const auto midx : kMapLocation.alMaps).

Related

How to solve the error syntax error, unexpected '=', expecting ')'?

i have code. but I can not understand why he swears?
This is line 17
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
**Parse error: syntax error, unexpected '=', expecting ')' in /home/s2332/***.com/www/admin/controller/shipping/novaposhta.php on line 17**
if (!empty($this->request->post['refresh']) && !empty($this->request->post['novaposhta_key'])) {
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $city_result;
} elseif (!empty($address_result = $this->model_module_novapochta->getAdress($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $address_result;
}
};
Your if statement is wrong...
You have write:
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
must be:
$city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']);
if (!empty($city_result)) {
//your code here

How to add debug information to trace the IR instructions(added in a custom pass) in LLVM?

I am writing a LLVM pass that would insert some codes into programs. Here is a minimal example, which inserts a function call to foo at the beginning of each basic block.
bool MyPass::runOnModule(Module &M) {
std::string foo = "_Z3foov";
LLVMContext &C = M.getContext();
Function *callee = M.getFunction(foo);
if (!callee) {
fprintf(stderr, "Unknown function %s", foo.c_str());
return false;
}
for (auto &F : M) {
if (F.getName().str() == foo) continue;
for (auto &BB : F) {
BasicBlock::iterator IP = BB.getFirstInsertionPt();
IRBuilder<> builder(&(*IP));
builder.CreateCall(callee, std::vector<Value *>(0), "call to foo"); // insert a new instruction.
}
verifyFunction(F);
}
return true;
}
I am seeking the way to locate all the inserted instructions(the call instruction in this example) in the binary after linking (e.g., the ELF format). I think one way to do that is to manipulate the debug information, and store the information in the DWARF sections.
But I can only find the debug information tutorial about how to map the source code to the binary. Is there a way to maintain the information of the manually-added codes?
I have tried a tricky idea: create a virtual source file. The code is just like this:
bool MyPass::runOnModule(Module &M) {
std::string foo = "_Z3foov";
DIBuilder *DBuilder = new DIBuilder(M);
DICompileUnit *CU = DBuilder->createCompileUnit(
dwarf::DW_LANG_C,
DBuilder->createFile("extra_debug_information.db", "."),
"MyPass", 1, "", 1);
DIFile *DFile = DBuilder->createFile(CU->getFilename(), CU->getDirectory());
LLVMContext &C = M.getContext();
Function *callee = M.getFunction(foo);
if (!callee) {
printf("Unknown function %s", foo.c_str());
return false;
}
size_t counter = 0;
for (auto &F : M) {
if (F.getName().str() == foo) continue;
DIScope *FContext = DFile;
DISubprogram *SP = DBuilder->createFunction(
FContext, "extra_debug_subprogram", "", DFile, 1,
DBuilder->createSubroutineType(DBuilder->getOrCreateTypeArray(None)),
DINode::FlagZero);
F.setSubprogram(SP);
for (auto &BB : F) {
BasicBlock::iterator IP = BB.getFirstInsertionPt();
IRBuilder<> builder(&(*IP));
counter++;
builder.SetCurrentDebugLocation(
DILocation::get(SP->getContext(), counter, counter, SP));
builder.CreateCall(callee, std::vector<Value *>(0), "call to foo");
}
verifyFunction(F);
}
M.addModuleFlag(llvm::Module::Warning, "Dwarf Version", 5);
M.addModuleFlag(llvm::Module::Error, "Debug Info Version",
llvm::DEBUG_METADATA_VERSION);
DBuilder->finalize();
return true;
}
But I got a warning like
clang++ -Xclang -load -Xclang ./libmypass.so test.cpp -emit-llvm -S
clang++ test.ll -o test
test.ll:74:6: error: Expected '!' here
!9 = <temporary!> !{}
^
1 error generated.
make: *** [Makefile:7: test] Error 1
I would be grateful if you could give some suggestions. Thank you very much.

Internal compile error c++ cilk plus

[Fixed]- Explanation given in comments
[Updated with error screenshot]
I am getting a compilation error when compiled using gcc/5.4.0. Following is the error reported:
internal compiler error: in lower_stmt, at gimple-low.c:397
cilk_spawn m_sparsify_graph_helper__(mdl, n_pa, n_ch, score2beat);
Following is the code snippet that causes error:
void m_sparsify_graph_helper__(MDL mdl, set_type pa, set_type ch, std::vector<double> score2beat) {
//cilk::reducer<cilk::op_list_append<RNode_>> rlist;
//"rlist" - defined in the class as a private variable
if (ch == 0) { return; }
set_type n_ch = ch;
// Some more code -- which I am very sure is not causing error
int lsb = n_ - 1;
for (; lsb >= 0; --lsb) { if (in_set(pa, lsb)) { break; } }
if (lsb == n_ - 1) { return; }
set_type n_pa = set_add(pa, lsb + 1);
int n_pa_sz = set_size(n_pa);
if (n_pa_sz >= n_) { return; }
BitCombination comb(n_pa, n_pa_sz, n_);
for (;;) {
n_pa = comb.data();
// If cilk_spawn keyword removed it compiles fine.
cilk_spawn m_sparsify_graph_helper__(mdl, n_pa, n_ch, score2beat);
if (!comb.next() || in_set(n_pa, n_ - 1)) { break; }
}
}// m_sparsify_graph_helper__
I assume it's a compiler error but I would like to know what is the way to circumvent this error and get the code executed warning and error free.
Error screenshot:
It seems the reported errors was ironed out in the GCC 6.X release.
FYI, if you are facing similar issue try to reproduce the error on the latest release of GCC just to confirm whether it was earlier reported and rectified or not.

Invalid Arguments in (std::string).find and (std::string).replace

I am using the following code to replace a string within a string.
The same code as below is working in Visual Studio 2012 but not in Eclipse, and I can't figure out why.
The error is about invalid arguments in the find and replace functions of std::string:
void ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace)
{
// handle error situations/trivial cases
if (search.length() == 0)
{
// searching for a match to the empty string will result in an infinite loop
return;
}
if (subject.length() == 0)
{
return; // nothing to match against
}
std::size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos)
{
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
}
The error message is as follows:
Invalid arguments '
Candidates are:
? find(const char *, ?, ?)
? find(const stlpmtx_std::basic_string<char,stlpmtx_std::char_traits<char>,stlpmtx_std::allocator<char>> &, ?)
? find(const char *, ?)
? find(char, ?)
'
Problem 1:-
Is there a different way to use these functions in Eclipse? What should I do to make the error go away?
Problem 2 :-
What does the ? sign mean in the error messages?

OGRE No suitable conversion function exists

I'm having a hard time trying to get an app to compile in Visual Studio 2013. I've solved a good amount of errors but I can't find a solution for the last one.
here it is:
void Application::setupRenderSystem() {
mState->dumpValues();
String val = mState->getStringValue("renderSystem");
RenderSystemList *renderSystems = mRoot->getAvailableRenderers();
RenderSystemList::iterator r_it;
bool renderSystemFound = false;
for (r_it = renderSystems->begin(); r_it != renderSystems->end(); r_it++) {
RenderSystem *tmp = *r_it;
std::string rName(tmp->getName());
// returns -1 if string not found
if ((int)rName.find(val) >= 0) {
mRoot->setRenderSystem(*r_it);
renderSystemFound = true;
break;
}
}
if (!renderSystemFound) {
OGRE_EXCEPT(0, "Specified render system (" + val + ") not found, exiting...", "Application")
}
}
Visual Studio indicates that the line RenderSystemList *renderSystems = mRoot->getAvailableRenderers(); is the problem, especially mRoot
Here is the error I get:
error C2440: 'initializing' : cannot convert from 'const Ogre::RenderSystemList' to 'Ogre::RenderSystemList *'
The getAvailableRenderers method doesn't return a pointer to a RenderSystemList. You'd want to have the value stored in a reference to a RenderSystemList:
RenderSystemList const& renderSystems = mRoot->getAvailableRenderers();
The Ogre API says:
const RenderSystemList & getAvailableRenderers (void)
So it returns a const reference and not a pointer.
Modify your code like this
const RenderSystemList &renderSystems = mRoot->getAvailableRenderers();