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.
Related
While trying to debug an issue with an assert macro I came across this problem. Using __declspec(noinline) on a lambda function in a template class generates a syntax warning in Visual Studio 2017:
error C2760: syntax error: unexpected token '__declspec', expected '{'
This is the failing code:
template<class R>
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // syntax error
}
};
int WinMain(void)
{
return 0;
}
If I go to my project settings and switch my platform toolset from v141 (vs2017) to v140 (vs2015) in the general section of the project properties dialog the error goes away .
If I change the class to not be a template class it also compiles correctly:
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // compiles fine
}
};
int WinMain(void)
{
return 0;
}
I'm curious why this wouldn't succeed using the v141 platform toolset. Is there some other project setting that could be affecting this?
I was able to fix this by updating Visual Studio 2017 to the latest version (15.9.7). Previously I was running version 15.6.7. Thanks to everyone who looked in and commented! :)
It works in VC++ 2019, so may just be a regression in 2017?
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.
The following code fails to compile in VS2015.
struct Foo
{
Foo(int value) { }
};
struct Moo
{
struct
{
Foo foo = 0;
} fooHolder;
};
int main()
{
Moo moo;
}
The following error is shown.
1>c:\xxx\main.cpp(81): error C2512: 'Foo' : no appropriate default constructor available
1> This diagnostic occurred in the compiler generated function 'Moo::<unnamed-type-fooHolder>::(void) restrict(cpu, amp)'
If the unnamed struct is given a name, the code compiles.
struct NamedHolder
{
Foo foo = 0;
} fooHolder;
The code compiled in clang and gcc. http://coliru.stacked-crooked.com/a/3b4ab035a967eed9
Is it rejecting valid code?
This code is perfectly fine and it compiles with VS2015 Update 1 RC (just verified). Maybe you're missing something . The system on which I tested :
Microsoft Visual Studio Community 2015
Version 14.0.24627.00 Update 1 RC
Microsoft .NET Framework
Version 4.6.01040
Installed Version: Community
Visual C++ 2015 RC 00322-20000-00000-AA392
Microsoft Visual C++ 2015 RC
...
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
I was compiling the following code in c++, Visual Studio 2012 (Professional, Update 4)
class dum {
stringstream *ss;
~dum() {
delete ss;
}
public:
dum() : ss(NULL) {}
};
int main()
{
dum a;
return 0;
}
Now I know that the private destructor would force heap allocated objects only, but I would expect a compile error for that. Instead I get a window titled "Microsoft (R) C/C++ Optimizing compiler" saying
Microsoft (R) C/C++ Optimizing compiler has stopped working. Windows can check online for a solution to the problem
and then the usual prompts to go online where nothing happens (or gets resolved). Am I doing something wrong or have I stumbled upon a bug in the compiler?
EDIT
The code I'm posting is all that's present in a win32 console program (even the main() has this no arguments form) and the only header included is sstream.
If you move the destructor to the public section of the class we no longer have a crash, but as I mentioned above this should be a cause for compilation error (namelly cannot access private member declared in dum) and not for this pop-up. The question's targeted to people that can provide an intrinsic or two about what's the problem with the compiler here, I've seen similar problems before, but that's the smallest code segment that caused such a thing.
Trying to compile the fixed version:
#include <sstream>
using namespace std;
class dum {
stringstream *ss;
~dum() {
delete ss;
}
public:
dum() : ss(NULL) {}
};
int main()
{
dum a;
return 0;
}
gives following compile error for me.
Tried this with VS2012 Ultimate Version 11.061030.00 Update4.
1>------ Build started: Project: dum, Configuration: Debug Win32 ------
1> dum.cpp
1>c:\users\randmaniac\documents\visual studio 2012\projects\dum\dum\dum.cpp(19): error C2248: 'dum::~dum' : cannot access private member declared in class 'dum'
1> c:\users\randmaniac\documents\visual studio 2012\projects\dum\dum\dum.cpp(8) : see declaration of 'dum::~dum'
1> c:\users\randmaniac\documents\visual studio 2012\projects\dum\dum\dum.cpp(6) : see declaration of 'dum'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
No crash for me on a fairly recent installation of VS2012.