error : identifier "__func__" is undefined with ICC - c++

I'm trying to compile my project with Intel's C++ Compiler but I'm getting many errors like these:
1>..\src\luascript.cpp(5889): error : identifier "__func__" is undefined
1> reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
1> ^
I've compiled this project with MS Visual Studio before and got no warnings or errors but with ICC I get this. Here is the section of code that produces that error
int32_t LuaScriptInterface::luaNetworkMessageAddItem(lua_State* L)
{
// networkMessage:addItem(item)
Item* item = getUserdata<Item>(L, 2);
if (!item) {
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); //This is the line that the error points to
lua_pushnil(L);
return 1;
}
//...
}
The definition reportErrorFunc is:
#define reportErrorFunc(a) reportError(__FUNCTION__, a, true)
There is also:
#ifndef __FUNCTION__
#define __FUNCTION__ __func__
#endif
Please let me know if you need me to post anymore code
I'm on Windows 7 SP1 x64 with MSVC 2013 Ultimate and Intel C++ Studio XE 2013 SP1 U2

Depending on the version of Intel XE the __func__ predeclared identifier may or may not be available. Make sure you use /Qstd=c++11 to enable its availability.
More information is availble at:
https://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler

Related

How to solve MSVC treatment of C++ function templates that is different than that of GCC/Clang (unrecognizable template definition)?

A template helper function exists
#include <iostream>
namespace helpers {
template <typename OUT = float, typename IN>
OUT normalizeFromRange(IN v, IN min, IN max) {
return static_cast<OUT>(v - min) / static_cast<OUT>(max - min);
}
}
int main()
{
float resultFAuto = helpers::normalizeFromRange<>(10, 0, 40);
float resultF = helpers::normalizeFromRange<float>(20, 0, 40);
double resultD = helpers::normalizeFromRange<double>(30, 0, 40);
std::cout << "resultFAuto: " << resultFAuto << std::endl;
std::cout << "resultF: " << resultF << std::endl;
std::cout << "resultD: " << resultD << std::endl;
return 0;
}
results in
resultFAuto: 0.25
resultF: 0.5
resultD: 0.75
It compiles on Clang, GCC, which are compilers I use. C++14.
I want to build the project also on MSVC++ and it compiles on online MSVC++ compiler that claims to be using 19.00.23506
But it fails on my machine that uses 19.16.27027.1, C++14 set.
Microsoft Visual Studio Community 2017
Version 15.9.9
VisualStudio.15.Release/15.9.9+28307.518
Installed Version: Community
Microsoft Visual C++ 2017
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1
with
error C2988: unrecognizable template declaration/definition
error C2059: syntax error: '('
error C2143: syntax error: missing ';' before '{'
error C2447: '{': missing function header (old-style formal list?)
Is the template function defined with incorrect syntax per spec (and GCC, Clang, some MSVC++ version(s) just somehow passes)?
Or is it something MSVC specific, MSVC flags specific, or yet recent MSVC specific?
Something else?
There is one similar issue, but my knowledge on templates does not allow to see, how it applies here.
Does your project include windows.h?
Including windows.h also brings in preprocessor defines for OUT and IN which I think is causing this error.
Changing the template typenames to OUTX and INX fixes the errors on my machine.
I found a related SO question: IN and OUT macros in minwindef.h

c++ std::sort intel compiler error : access violation

Why does this simple c++ code snippet do not compile?
#include <algorithm>
#define SIZE (1000)
struct S {
int *vect;
};
int main() {
struct S* s = static_cast<struct S*>(malloc(sizeof(struct S)));
s->vect = static_cast<int*>(malloc(sizeof(int) * SIZE));
for(int i = 0; i < SIZE; i++) {
s->vect[i] = i;
}
std::sort(s->vect, s->vect + SIZE);
}
The compiler returns the following error related to the std::sort call
1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\algorithm(3138):
error : access violation
1> return (pair<_RanIt, _RanIt>(_Pfirst, _Plast));
1> ^
I'm using visual studio enterprise 2017 version 15.5.2 and the intel compiler 64 bit version 17.0.4.210 Build 20170411.
The code is successfully compiled using the default visual studio compiler.
Can't find out what I'm doing wrong.
I've found out that unfortunately visual studio update 15.5.x breaks Intel Compiler 2017 as can be seen in the intel forum where I asked this same question. Hope it will be useful to others too.

error C2143: syntax error : missing ',' before ':'

I'm trying to build am opensource game but keep getting this error when trying to build. I have been searching for the last half hour with nothing working here's the code the errors pointing to
void duel::restore_assumes() {
for(auto pcard : assumes)
pcard->assume_type = 0;
assumes.clear();
}
and the error is
Error 1 error C2143: syntax error : missing ',' before
':' c:\users\user\desktop\project source\ocgcore\duel.cpp 108 1 ocgcore
(Visual Studio 2010)
MS VC++ 2010 does not support the range based for statement that was introduced in the C++ 2011. However it has its own language extension: for each.
Try to change this code
void duel::restore_assumes() {
for(auto pcard : assumes)
pcard->assume_type = 0;
assumes.clear();
}
to
void duel::restore_assumes() {
for each (auto pcard in assumes)
pcard->assume_type = 0;
assumes.clear();
}
Otherwise you can use an ordinary loop with iterators of object assumes or some standard algorithm as for example std::for_each
As shown in this table : C++11 Compiler Support
Range-based for Loops aren't available with MSVC2010, but with MSVC2012 (which is version 11).
So if you use the 2010 compiler, this code won't compile.
The error message makes it pretty obvious: the compiler is not expecting a : in the for statement.

Delegating Constructors in VS11

I'm trying to use delegate constructors in Visual Studio 2012 Update 3, but I'm getting an error:
$> cl.exe /EHsc /W4 /MTd .\bla.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.60610.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
bla.cpp
.\bla.cpp(6) : error C2614: 'Bla' : illegal member initialization: 'Bla' is not
a base or member
Example source file:
#include <iostream>
class Bla {
public:
Bla() : Bla(10) { std::cout << "bla()" << std::endl; }
Bla(int _n) { std::cout << "bla(int): " << _n << std::endl; }
};
int main()
{
Bla b0;
Bla b1(10);
}
It seems to have worked before and is described in this video (starting around 31:30).
Can someone tell me the status of the implementation of delegate constructors in Visual Studio 2012? Or am I doing something wrong? Maybe my cl.exe command? Or do I need to install some CTP compiler or something?
Or do I need to install some CTP compiler or something?
Indeed. Delegating constructors are not supported on official releases/updates of VS2012. You have to install November 2012's CTP.
Here is a summary of C++11 features supported (and not supported) by VC11.

C2440 'initialising': Cannot convert int to unsigned char* in Microsoft VS 2010 utility file

When I compile my VS 2010 C++ project the following passage raises an error in file c:\program files\microsoft visual studio 10.0\vc\include\utility
template<class _Other1,
class _Other2>
_Pair_base(_Other1&& _Val1, _Other2&& _Val2)
: first(_STD forward<_Other1>(_Val1)),
second(_STD forward<_Other2>(_Val2))
{ // construct from moved values
}
The error is then followed by another error C2439 'std::_Pair_base..::first element could not be converted'
(All errors translated from German, so they may sound slightly different in English)
I am trying to compile the AxCrypt project on VS 2010, the project files have automatically been converted from VS 2008 (but I don't know if it would work there, I only have VS 2010).
The problem was in the Crypto++ lib used which needs two small modifications before compiling on VS 2010.
a) pubkey.h line 243:
return HashIdentifier(NULL, 0);
->
return HashIdentifier((const byte*)NULL, 0);
b) zdeflate.cpp line 389
#if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && _MSC_VER < 1400)
&& !defined(_STLPORT_VERSION)
->
#if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && (_MSC_VER < 1400
|| _MSC_VER >= 1600)) && !defined(_STLPORT_VERSION)
More details here:
http://groups.google.com/group/cryptopp-users/browse_thread/thread/714f3ec6287a50b1
This code can reproduce this error:
pair<int,char*> aPair(10,20);
Since second type I specified is of char* but I am passing an int, which cannot be converted to char*.
Note that this is oversimplified sample for the error you might be encountering. Probably you are using a map.